Copy link to clipboard
Copied
Hi,
I have multiple movieclips, each with 5 image-movieclips inside, which allows me to manipulate which image-movieclip is displayed in an animation. So, if image-mc1.alpha = 0, then image-mc2, next in the 5 layers, which has a default alpha of 1 is displayed. 5 image-mc's, so can use alpha to show whichever is needed.
There are 37 of these image-mc's in the project.
Instead of a FLA based project, I would like to try a pure-AS3 version, maybe compile using Flex/AIR SDK. One way to re-use these complex mc's would be a create a SWC for each (not sure one SWC with all 37 can be created in CS6, or how each would be called in the script?).
When I try this, using one multi-mc/multi-layer mc exported as a SWC and try to reference its internal mc's re: alpha setting, doesn't work.
image1.imagea1.alpha = 0;//image1 is the instantiated version of the SWC's mc done as addChild(image1)
In the FLA version, this script would cause the second mc, imageb1, which has a default alpha of 1, to display. But this is not happening in the AS3 version. Instead, image1.imagea1 still displays, no alpha effect.
Any way to get this to work?
you can just remove the child movieclips that you don't want to be seen:
displayF("imagea1");
function displayF(mcS:String):void{
for(var i:int=0;i<image1.numChildren;i++){
if(image1.getChildAt(i).name!=mcS){
image1.removeChild(image1.getChildAt(i));
}
}
Copy link to clipboard
Copied
you can just remove the child movieclips that you don't want to be seen:
displayF("imagea1");
function displayF(mcS:String):void{
for(var i:int=0;i<image1.numChildren;i++){
if(image1.getChildAt(i).name!=mcS){
image1.removeChild(image1.getChildAt(i));
}
}
Copy link to clipboard
Copied
Thank you for this helpful suggestion.
The other issue is whether all of the 37 mc's can be exported in one SWC, instead of 37 separate SWC's?
If yes, how (for an individual mc, can right-click it in the library, not even on stage, to export as SWC? And once added to the Flex/AIR IDE, how to reference one or another in the AS3, since there would only be one class name for all?
Copy link to clipboard
Copied
they can all be exported in one swc by making them all children of one parent movieclip and exporting the parent as a swc. they would each need an instance name and you could use those to display the movieclip you wanted.
for example, if your movieclip parent (exported as swc) has class P:
var p:P=new P();
addChild(p);
displayF("imagea1");
Copy link to clipboard
Copied
Again, thank you.
I guess what I'm not clear about is how to add/call each in the script. For example, the mc's are p1...p37. (As mentioned, each of these has 5 subordinate mc's inside with images.)
So, if I create all 37 as class P, how would I instantiate each one of the 37 separately?:
var p1:P=new P();
addChild(P.p1);
//and
var p2:P=new P();
addChild(P.p2);
//etc...
var p37:P=new P();
addChild(P.p37);
Then
displayF("p37.imagea1");
I'm not sure how to reference/script these.
Copy link to clipboard
Copied
only the parent has movieclip has a class assigned. the child movieclips are referenced by their instance names (assigned when you add them to the parent) just like i showed above:
var p:P=new P();
add(p);
displayF("p1");
and any time you want to reference "p1", use:
p.getChildByName("p1");
or, even easier, amend displayF:
var p:P=new P();
add(p);
var p1:MovieClip = displayF("p1");
// p1 is now a reference to your child movieclip with instance name "p1".
function displayF(mcS:String):MovieClip{
for(var i:int=0;i<image1.numChildren;i++){
if(image1.getChildAt(i).name!=mcS){
image1.removeChild(image1.getChildAt(i));
}
return image1.getChildByName(mcS);
}
///////////////////////////////////
if you want to add p1,p2 and p3:
var p:P=new P();
add(p);
var p1:MovieClip = displayF("p1");
p=new P();
add(p);
var p2:MovieClip = displayF("p2");
p=new P();
add(p);
var p3:MovieClip = displayF("p3");
Copy link to clipboard
Copied
Thank you again.
I'm slowly working my way through this, making progress, learning with your help.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now