Copy link to clipboard
Copied
Hi!
I'm starting to learn AS3.0 with a book from 2011 and most things seem to function the same.
However, I'm having trouble accessing nested movie clips inside other movie clips.
I created a new simple document just to try this:
I made a movie clip called "square", and inside it I made another movie cilp called "circle".
Then, back on the main stage I created a "button" movie clip to manipulate the "circle" movie clip (which worked just fine).
However, when I tried to make a simple trace statement with a Mouse Over function on to the "circle" movie clip, it doesn't work:
Code |
---|
import flash.events.MouseEvent; //Here, the function accesses the "circle" movieclip buttonCircle.addEventListener(MouseEvent.CLICK, changeCircle); function changeCircle(e:MouseEvent):void { square.circle.gotoAndStop("yellow"); } //Here, I can't access the circle movieclip square.circle.addEventListener(MouseEvent.MOUSE_OVER, overCircle); function overCircle(e:MouseEvent):void { trace("Circle"); } |
I get the following message on the Output:
Output |
---|
TypeError: Error #1010: A term is undefined and has no properties. at Untitled_1_fla::MainTimeline/frame1() |
Does anyone know why this happens?
Thanks a lot in advanced.
1 Correct answer
Check your Document Settings and be sure "Advanced Layers" is toggled off. With it on, it creates an additional symbol based on the entire layer name. Alternatively, you can try something like: square1.LAYER_NAME.circle1 or whatnot.
Copy link to clipboard
Copied
is circle in frame 1 of square?
Copy link to clipboard
Copied
It is on the first frame of the "square" movie clip, but on a second layer.
However, that doesn't seem to be a problem with the first function.
Copy link to clipboard
Copied
click file>publish settings and tick 'permit debugging'. retest.
the problematic line of code will be in the error message. if that line of code is:
square.circle.addEventListener(MouseEvent.MOUSE_OVER, overCircle);
either there is no square instance in the frame that contains the above code or there's no circle instance in frame 1 of square.
Copy link to clipboard
Copied
The new error message shows this:
TypeError: Error #1010: A term is undefined and has no properties.
at Untitled1_fla::MainTimeline/frame1()[Untitled1_fla.MainTimeline::frame1:175]
I've just double-checked:
- the code is on the first frame.
- the movie clip on that first frame has the instance name "square".
- the circle is on the first frame of this "square" instance (I've even tried placing it on the same layer as the square drawing).
- that "circle" movieclip has the instance name "circle".
As I said, this confuses me, because the first function of the same code (changeCircle) does use the "square.circle" method, and it works perfectly 😕
Either way, thanks kglad!
Copy link to clipboard
Copied
what's line 175 in frame 1 of Untitled1's main timeline??
Copy link to clipboard
Copied
There isn't any.
That's all the code I wrote, it ends on line 16.
(The post made it seem bigger, but it's only sixteen lines)
Copy link to clipboard
Copied
start a new fla
recreate your button and square movieclip with circle movieclilp.
retest.
Copy link to clipboard
Copied
I did it all over again in a new file but got the same result.
I even tried creating the instances of both movie clips with AS, but the Output still displayed the same TypeError:
Code:
var square1 = new square();
square1.x = 100;
square1.y = 100;
addChild(square1);
var circle1 = new circle();
square1.addChild(circle1);
square1.circle1.addEventListener(MouseEvent.MOUSE_OVER, overCircle1);
function overCircle1(e:MouseEvent):void {
trace("this is the circle")
}
Output:
TypeError: Error #1010: A term is undefined and has no properties.
at Untitled_2_fla::MainTimeline/frame1()[Untitled_2_fla.MainTimeline::frame1:171]
Copy link to clipboard
Copied
Hi.
Instead of:
square1.circle1.addEventListener(MouseEvent.MOUSE_OVER, overCircle1);
write:
circle1.addEventListener(MouseEvent.MOUSE_OVER, overCircle1);
Instances added and nested at runtime cannot be referenced with dot notation like you would do with objects created by the IDE.
The reference to your circle is stored in the circle1 variable no matter the parent.
Regards,
JC
Copy link to clipboard
Copied
Thanks, João!
On the second scenario (where I created the instances on the Actions panel, instead of the stage) that solved the problem as well.
On my original problem (the one described on the first post) the instances where on stage, so it was actually the "Advanced layers" thing.
Copy link to clipboard
Copied
Check your Document Settings and be sure "Advanced Layers" is toggled off. With it on, it creates an additional symbol based on the entire layer name. Alternatively, you can try something like: square1.LAYER_NAME.circle1 or whatnot.
Copy link to clipboard
Copied
Thanks a lot, Joseph!
That was it!
Copy link to clipboard
Copied
if advanced layer were the problem the first code snippet wouldn’t work.

