|
-
[RESOLVED] Control of dynamic, nested MovieClips
I have the following AS:
Code:
function regionRollOver(evt:MouseEvent):void
{
var mc:String = evt.target.name;
mc = mc.replace("target_", "");
mc = mc.replace("_mc", "");
map_mc.MovieClip("target_" + mc + "_mc").alpha = .5;
} //regionRollOver()
The idea is to basically allow a name of the evt to be stripped of "target_" and "_mc" so it can be used multiple times in different MovieClip variations.
The mc MovieClip is nested in map_mc. I get the following error when trying to run the code:
Code:
TypeError: Error #1006: MovieClip is not a function.
at private_fla::MainTimeline/regionRollOver()
Can anybody help me to be able to control nested MovieClips that are referenced on the fly?
Thanks in advance,
-
Maybe, just maybe, the error message might be telling you what is wrong. MovieClip is not a function.
You want getChildByName.
Actually, looking at that code, I have no idea why you're messing with the name at all.
Code:
function regionRollOver(evt:MouseEvent):void
{
MovieClip(evt.target).alpha = .5;
} //regionRollOver()
-
I would normally use this approach, but I have two movieclips that I want to control with dynamic reference:
Code:
target_variable_mc
text_variable_mc
... where "variable" is the stripped term. Both clips are within map_mc.
-
Then you want getChildByName.
Code:
function regionRollOver(evt:MouseEvent):void
{
var mc:String = evt.target.name;
mc = mc.replace("target_", "");
mc = mc.replace("_mc", "");
map_mc.getChildByName("target_" + mc + "_mc").alpha = .5;
map_mc.getChildByName("text_" + mc + "_mc").alpha = .5;
} //regionRollOver()
<Insert standard rant about how naming conventions are awful.>
-
I am also trying to target a MovieClip inside the given clip - using the above code does not work:
Code:
map_mc.getChildByName("target_" + mc + "_mc").target_mc.gotoAndPlay("over");
Is this approach incorrect?
-
If it does not work, then it is incorrect. But since you didn't provide any details about HOW it doesn't work, I have to guess.
I guess that it's complaining that there is no target_mc property on DisplayObject. You need to cast to MovieClip in order to access dynamic properties. Or, you can use getChildByName again if that's more appropriate.
Code:
MovieClip(map_mc.getChildByName("target_" + mc + "_mc")).target_mc.gotoAndPlay("over");
Or
Code:
MovieClip(DisplayObjectContainer(map_mc.getChildByName("target_" + mc + "_mc")).getChildByname("target_mc")).gotoAndPlay("over");
-
Yes, sorry for not providing more details; the above codes produce the following error:
Code:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at private_fla::MainTimeline/regionRollOver()
-
Ah. Well that means you don't actually have a child being returned from the getChildByName statement. So either things are not structured as you think they are, or I misunderstood. Is there a direct child with the name target_variable_mc on map_mc?
-
The following structure applies:
ROOT > map_mc > target_variable_mc > target_mc
What was interesting, is that I targeted the target_variable_mc and made the alpha = .5; which worked!
But when I try to target the target_mc and play the target_mc frame labeled "over", it does not work...
-
Debug time.
Code:
var d:DisplayObjectContainer = DisplayObjectContainer(map_mc.getChildByName("target_" + mc + "_mc"));
trace("target_"+mc+"_mc is:"+d);
var tmc:MovieClip = d.getChildByName("target_mc");
trace ("target_mc is:"+tmc);
tmc.gotoAndPlay("over");
I'm guessing you will get "target_mc is: null" and then an error.
-
Sorry, your initial code was correct, I had incorrectly targeted the MovieClip - thank you very much for your help!
Tags for this Thread
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
|