• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Accessing nested movie clips with ActionScript 3.0

Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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.

Views

964

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 16, 2019 Jul 16, 2019

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.

Votes

Translate

Translate
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

is circle in frame 1 of square?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

what's line 175 in frame 1 of Untitled1's main timeline??

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

start a new fla

recreate your button and square movieclip with circle movieclilp.

retest.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

Thanks a lot, Joseph!

That was it!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

LATEST

if advanced layer were the problem the first code snippet wouldn’t work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines