views:

475

answers:

2

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.

A: 

You should not be listening for the drag on "sprite". You need separate listeners and handlers for each child that you want draggable. So instead you need to listen on the child of "sprite":

sprite.loader.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); 
sprite.loader.addEventListener(MouseEvent.MOUSE_UP,dropIt);

Also you should be dragging the child, not your "sprite" container:

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

Im not sure what you are trying to accomplish with the for while loop, but here is an example of a basic for loop that creates a bunch of loader variables:

var loaderArray:Array = [];
for(var increment = 0; increment < numberOfUploads; increment++) {
    loaderArray[increment]:URLLoader = new URLLoader();
}

I hope that is helpful. It would be better if we could see more of your code.

Armitage
I want to target each image with a different name so that I can drag/drop size up/down. private function complete(event:Event):void { function imgVal():Number { img += 1; return img; } imgVal(); var sprite:Sprite=new Sprite(); sprite.addChild(loader); sprite.name = "pict" + img; trace(sprite.name); _fla.myBorder.box.addChild(sprite); _fla.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); _fla.addEventListener(MouseEvent.MOUSE_UP,dropIt); This gives me the same name for each sprite pict1 instead of pict1, pict2, etc.Thanks Annette B.
Annette B
Sounds like you have everything you need. You do need to know the number of children you are trying to add (numberOfUploads, in my above code). Also, you need to increment the sprite name (img in your code is increment in my code). Also, you are changing the name of "sprite", why are you not changing the name of the children you are adding?
Armitage
A: 

Hello Annete.

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.

George Profenza
I want to target each image with a different name so that I can drag/drop size up/down. private function complete(event:Event):void { function imgVal():Number { img += 1; return img; } imgVal(); var sprite:Sprite=new Sprite(); sprite.addChild(loader); sprite.name = "pict" + img; trace(sprite.name); _fla.myBorder.box.addChild(sprite); _fla.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); _fla.addEventListener(MouseEvent.MOUSE_UP,dropIt); This gives me the same name for each sprite pict1 instead of pict1, pict2, etc.Thanks Annette B.
Annette B
I have changed your code a bit: private var imgNum:int;private function complete(event:Event):void { imgNum++ var sprite:Sprite=new Sprite(); sprite.addChild(loader); sprite.name = "pict" + imgNum; trace(sprite.name); _fla.myBorder.box.addChild(sprite); sprite.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); sprite.addEventListener(MouseEvent.MOUSE_UP,dropIt);}function pickUp(event:MouseEvent):void{ trace(event.currentTarget.name);}function imgVal():Number { img += 1; return img; } imgVal(); is the same as incrementing a number by one for which you have the ++ operator.
George Profenza
what I used:imgVal(); var sprite:Sprite=new Sprite(); sprite.addChild(loader); sprite.name = "pict" + imgNum; trace(sprite.name); _fla.myBorder.box.addChild(sprite); sprite.addEventListener(MouseEvent.MOUSE_DOWN,pickUp); //sprite.addEventListener(MouseEvent.MOUSE_UP,dropIt); } function pickUp(event:MouseEvent):void { trace(event.currentTarget.name); } function imgVal():Number { img += 1; return img; }Still each uploaded photo has the name pict0 and each additional photo uploaded also has the name pict0. Would like to have each one be pict1, pict2 etc.thanks
Annette B
Annette, have were you able to read what I have written ? Bottom line is: function imgVal():Number { img += 1; return img; } can be written as img++ . It depends where you delcare img in the first place, and that should be outside your complete function. I am not sure what you don't understand so I can try to explain better
George Profenza
I have tried your solution but so far I am still the same result, that the variable is not increasing. I did find a Flash CS3 tutorial called Display Programming with examples of targeting and moving various sprites around the stage. I will work through the examples. Hopefully I will find the solution there. Thanks again for taking the time to respond.
Annette B