Reputation: 311
I want to be able to convert everything I have added on stage to a MovieClip through ActionScript.
So lets say I now have:
stage.addChild(pic1);
stage.addChild(pic2);
where pic1
andpic2
are instances of a MovieClip I have,
now after this I want to make both of these together into a MovieClip through code and be able to access that MovieClip object.
Upvotes: 0
Views: 1050
Reputation: 8111
Container which allows interactivity eg. click detection
var sprite:Sprite = new Sprite();
sprite.addChild(pic1);
sprite.addChild(pic2);
As per crooksy88 answer above, though I am not sure what the benefits would be to use a MovieClip in this scenario
Upvotes: 0
Reputation: 86
If you are looking for a quick way to re-parent everything on the stage whether you know the instance names or not, you'll have to loop through all the children of the stage.
var myMovieClip:MovieClip = new MovieClip(); // the MovieClip to contain your children
var l:int = stage.numChildren; // how many things are on the stage
for (var i:int = 0; i<l; i++){ // loop through all of them
myMovieClip.addChild(stage.getChildAt(0)); //removes the bottom DisplayObject from the stage and adds it to your container
}
addChild(myMovieClip); //adds the complete MovieClip back to the stage;
Upvotes: 1
Reputation: 39456
Stage
and MovieClip
both inherit from DisplayObjectContainer
, which defines the method addChild()
.
This means that you can easily create a MovieClip
and add that to the stage:
var container:MovieClip = new MovieClip();
stage.addChild(container);
And then add other DisplayObjects into that:
container.addChild(pic1);
container.addChild(pic2);
Manipulating position, scale, rotation and other similar properties will affect the contents of the container.
Upvotes: 0
Reputation: 3851
var newMC:MovieClip = new MovieClip();
newMC.addChild(pic1);
newMC.addChild(pic2);
Upvotes: 0