Passionnés d'informatique depuis 1990

FLASH/AS3:Déplacer plusieurs clips avec un seul drag

Par le 1 Juil 2009 dans Documentation | 0 comments

Drag multiple objects

Cette astuce vous permet de déplacer plusieurs display-objects avec une seule et même action startDrag.

Hint for dragging several objects at same time with single startDrag action.

Tip for moving several movieclips along with same drag action

[A & B are 2 MovieClips already on Stage]:

import flash.display.MovieClip;

A.addEventListener (MouseEvent.MOUSE_DOWN, _startDrag)

B.addEventListener (MouseEvent.MOUSE_DOWN, _startDrag)

var tempDraginClip:MovieClip

 

function _startDrag(e)

{

tempDraginClip = new MovieClip

addChild(tempDraginClip)

tempDraginClip.addChild(A)

tempDraginClip.addChild(B)

tempDraginClip.startDrag()

tempDraginClip.addEventListener(MouseEvent.MOUSE_UP, _stopDrag)

}

function _stopDrag(e)

{

addChild(A)

addChild(B)

A.x += tempDraginClip.x

A.y += tempDraginClip.y

B.x += tempDraginClip.x

B.y += tempDraginClip.y

removeChild(tempDraginClip)

tempDraginClip = null

}

points3Ligne

Publiez une réponse

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *