简体   繁体   中英

How can i change a couple of MovieClip instance properties in mainTimeline by ActionScript 3

I'm a beginner at ActionScript 3. I want to change a MovieClip property. Also I want to give different names for every instance. So basically I want to reach all instances by one name.

A possible solution is writing code inside the MovieClip timeline with --this--.

But I want to do that in root area.

This a picture of my scene: https://drive.google.com/file/d/0BzXd1GMzUo9HUWozdkJjYkxXSEk/view?usp=sharing

trace(ins1.alpha); // reaching with instance name without problem
trace(ins2.alpha); // reaching with other instance name without problem
/*
trace(MovieClip("mnsmb").alpha);        // trying to reach with linkage name is not working
trace(MovieClip(mnsmb).alpha);          // trying to reach with linkage name is not working
trace(MovieClip("menusembolu").alpha);  // trying to reach with library symbol name is not working
trace(MovieClip(menusembolu).alpha);    // trying to reach with library symbol name is not working
trace(mnsmb.alpha);                     // trying to reach with linkage name is not working
trace(menusembolu.alpha);               // trying to reach with library symbol name is not working
*/

If you need to modify the alpha property of one instance (named inst1 in the Properties panel):

ins1.alpha = 0.1;

If you want modify the alpha of all the instances of your class , you can use the is operator ( mnsmb is your AS Linkage):

var inst:DisplayObject;

for(var i:int = 0; i < numChildren; i++)
{
    inst = this.getChildAt(i) as DisplayObject;
    if (inst is mnsmb) inst.alpha = 0.1;
}

Note : In ActionScript 3.0 the instanceof operator should not be used to test for data type membership. See Adobe help about the is operator .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM