Copy link to clipboard
Copied
Hi,
I have a movie clip in my library and I would like to display it on the stage using AS3.
do I have to define it as a variable?Do I need to use this code: addchild(movieclip);
can I use the 'x' and 'y' to position it?
What would the code look like?
Ben.
Steps:
var movie:mov_clip = new mov_clip;
movie.x = 50;
movie.y = 50;
addChild:(movie);
Copy link to clipboard
Copied
Steps:
var movie:mov_clip = new mov_clip;
movie.x = 50;
movie.y = 50;
addChild:(movie);
Copy link to clipboard
Copied
Typo: no colon in addChild
Copy link to clipboard
Copied
Great! it works well ! thanks
But I have another question, if I wanted to used the same movie clip but postion it at different x and y positions when a different btn is selected how could I do that?
Would I have to make a copy of the movie clip and give it a different name?
or is there an better way around it?
Ben.
Copy link to clipboard
Copied
While the movieclip is added to the stage with addChild, you can move it around by assigning it's x and y properties anytime you like. So on a button press, just position it wherever you like.
Copy link to clipboard
Copied
Ok..
But I guess the problem I have is that I want this one moive clip to be in two different places at the same time! I have two different buttons but I want to display the same movie clip when both buttons are pressed independently so the move clip will have to be at two different locations!
Copy link to clipboard
Copied
Why not create two instances of that movie clip class?
var mc1:YourMcInLibrary = new YourMcInLibrary();
var mc2:YourMcInLibrary = new YourMcInLibrary();
mc1.x = 50;
mc1.y = 50;
mc2.x = 150;
mc2.y = 150;
addChild(mc1);
addChild(mc2);
Copy link to clipboard
Copied
Perfect !! you are a legend!!
thanks very much Harry.
Cheers,
Ben.
Copy link to clipboard
Copied
I hope the follwing basic method will work.
var movie:box=new box();
var movie1:box=new box();
butn.addEventListener(MouseEvent.CLICK,btnpressed);
function btnpressed(etc:MouseEvent):void{
movie.x=50;
movie.y=100;
movie1.x=200;
movie1.y=100;
addChild(movie);
addChild(movie1);
}
Copy link to clipboard
Copied
Fantastic! Thank you.
Copy link to clipboard
Copied
You're welcome!
Copy link to clipboard
Copied
Thanks Spvr, works well thanks.
I had another question which I repied to the wrong person!! would you mind having a look at my last post?
Cheers,
Ben.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more