Показать сообщение отдельно
Старый 10.06.2007, 15:50
p.kiev.ua вне форума Посмотреть профиль Отправить личное сообщение для p.kiev.ua Найти все сообщения от p.kiev.ua
  № 7  
Ответить с цитированием
p.kiev.ua

Регистрация: Jun 2007
Сообщений: 60
Цитата:
Сообщение от vvk80
ищем в встроенном help по ключ слову startDrag (как и в AS 2.0)
получаем след. код
Код:
circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown) 

function mouseDown(event:MouseEvent):void
{
    circle.startDrag();
}
circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);

function mouseReleased(event:MouseEvent):void
{
    circle.stopDrag();
    trace(circle.dropTarget.name);
}
спасибо большое, но не понятно к какой кнопке оно привязуется? я вставил этот код в кадр и создал кнопку - квадрат ... но этот квадрат я же должен както обозвать чтоб именно этот квадрат двигался...

в годе ненашел привязку к квадрату... помогите... я наверное чего-то непонимаю... у меня не работает!

Цитата:
Сообщение от vvk80
ищем в встроенном help по ключ слову startDrag (как и в AS 2.0)
получаем след. код
Код:
circle.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown) 

function mouseDown(event:MouseEvent):void
{
    circle.startDrag();
}
circle.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);

function mouseReleased(event:MouseEvent):void
{
    circle.stopDrag();
    trace(circle.dropTarget.name);
}
кстате в хелпе я покопался и нашел такой код:

Код:
// This code creates a drag-and-drop interaction using the mouse-following
// technique.
// circle and square are DisplayObjects (e.g. MovieClip or Sprite 
// instances).

import flash.display.DisplayObject;
import flash.events.MouseEvent;

var offsetX:Number;
var offsetY:Number;
var draggedObject:DisplayObject;

// This function is called when the mouse button is pressed.
function startDragging(event:MouseEvent):void
{
    // remember which object is being dragged
    draggedObject = DisplayObject(event.target);
    
    // Record the difference (offset) between where the cursor was when
    // the mouse button was pressed and the x, y coordinate of the
    // dragged object when the mouse button was pressed.
    offsetX = event.stageX - draggedObject.x;
    offsetY = event.stageY - draggedObject.y;
    
    // move the selected object to the top of the display list
    stage.addChild(draggedObject);
    
    // Tell Flash Player to start listening for the mouseMove event.
    stage.addEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}

// This function is called when the mouse button is released.
function stopDragging(event:MouseEvent):void
{
    // Tell Flash Player to stop listening for the mouseMove event.
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, dragObject);
}

// This function is called every time the mouse moves,
// as long as the mouse button is pressed down.
function dragObject(event:MouseEvent):void
{
    // Move the dragged object to the location of the cursor, maintaining 
    // the offset between the cursor's location and the location 
    // of the dragged object.
    draggedObject.x = event.stageX - offsetX;
    draggedObject.y = event.stageY - offsetY;
    
    // Instruct Flash Player to refresh the screen after this event.
    event.updateAfterEvent();
}



square.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
square.addEventListener(MouseEvent.MOUSE_UP, stopDragging);


он работает, но думаю там много лишнего ... может подскажешь что убрать из него?


Последний раз редактировалось etc; 10.06.2007 в 19:25.