-
Add Child Event in Loop Problem AS3!!
I am trying to create this as2 script file into as3:
PHP Code:
for(i=0;i<100;i++){
attachMovie("circle","circle"+i,i,{_x:Math.random()*550,_y:Math.random()*400});
}
for(i=0;i<100;i++){
_root["circle"+i].onPress=function(){
removeMovieClip(this);
}
}
Can some one please help me iv looked on lots of tutorials im one of the many people learning as3 that cant do this because either there isnt a way or it is very complex.
I can attach multiple movie clips but i cant remove them on click but give me the code for both any way so it makes sence thanks.
ps dont send me to another topic that has nothing to do with it like a passing variable topic thanks.
Alex.
-
Originally Posted by as3porgrammer
ps dont send me to another topic that has nothing to do with it like a passing variable topic thanks.
lol. I'm guessing this has happened before? Some people don't think before they post, just ignore them.
You can try this:
Code:
import flash.events.MouseEvent;
import Circle;
...
for(var i:int = 0; i < 100; i++)
{
var circle:Circle = new Circle();
circle.x = Math.random() * 550; // alternatively you could use stage.stageWidth instead of 550
circle.y = Math.random() * 400; // or stage.stageHeight here.
circle.addEventListener(MouseEvent.CLICK, onClickCircle);
addChild(circle);
}
function onClickCircle(event:MouseEvent):void
{
var circle:Circle = Circle(event.target);
circle.parent.removeChild(circle);
}
Make sure to assign the circle Library item with a Circle class in the same folder as the FLA of your project.
-
Martin Munoz Thank you so much Iv basicly been trying for 4 days to learn how to do this. + rep you
ps. yes i hate it when people send you to another forum that has nothing to do with the topic xD.
Last edited by as3porgrammer; 10-28-2007 at 05:19 AM.
-
Also one more thing how would I do
if(obj.hitTestObject(square)){
removeChild(square);
}
how would that work thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|