R – AS3 — Can upload several images to stage, want to size and move each separately

actionscript-3sprite

Currently each loader is a child of a sprite — sprite.addChild(loader);

Next I add the sprite to movieClip box which is with myBorder movieClip — mainMovie.myBorder.box.addChild(sprite);

Next I can drag the sprite using —

mainMovie.addEventListener(MouseEvent.MOUSE_DOWN,pickUp);
mainMovie.addEventListener(MouseEvent.MOUSE_UP,dropIt);

function pickUp(event:MouseEvent):void
{
sprite.startDrag();
}

 function dropIt(event:MouseEvent):void
 {
sprite.stopDrag();
 }

I want each sprite separate but I'm having trouble understanding where to use the "for while" loop. I only want to give the ability to upload 5 images at most.

Can anyone here help me?
Thanks Annette B.

Best Answer

A simple for loop should do

so instead of

mainMovie.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); mainMovie.addEventListener(MouseEvent.MOUSE_UP,dropIt);

you should have, assuming you have no other clips inside box, but the sprites that hold the loaders, and you need to make sure the sprites are added there. You should probably use the for loop to add the sprites and the listeners, but I cannot advise you accurately as I don't have enough information

for(var i:int = 0 ; i < 5 ; i++){
    mainMovie.myBorder.box.getChildAt(i).addEventListener(MouseEvent.MOUSE_DOWN,pickUp);;
}
stage.addEventListener(MouseEvent.MOUSE_UP,dropIt);

Ok, explanations:

a for loop is a simple yet powerful language element. I suggest reading the documentation, copying and pasting the example code in a new fla, tweaking and getting the hang of it. It's not as hard as it may seem.

I am adding the MOUSE_UP handler on the stage, because in as3 there is a issue with that. in as2 release outside works.

Related Topic