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

Referencing a "Nested" MovieClip or "childMovieClip"

New Here ,
Jun 02, 2014 Jun 02, 2014

Hello all.

I am fairly new to Flash and AS3 so bare with me. I am designing a simple interactive animation. In this interactive file, I have a tree branch. I have a button (leaves_btn) near the branch that once clicked, about 8 leaves will bloom from the tree. I have all of the leaves compressed into a childMovieClip labeled as "leaves8". I am having trouble getting the button on the main timeline to play my "leaves8" movieclip that is nested.

Any help would be greatly appreciated.

TOPICS
ActionScript
253
Translate
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
LEGEND ,
Jun 02, 2014 Jun 02, 2014

What is the code you are using that you are having trouble with?  Do you get any error messages?

Translate
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
New Here ,
Jun 02, 2014 Jun 02, 2014

theleafbtn.addEventListener(MouseEvent.CLICK, thefunction);

function thefunction(event:MouseEvent):void {

    leaves8.gotoAndPlay(1);

}

ERROR:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

  at Untitled_1_fla::MainTimeline/thefunction()

Translate
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
LEGEND ,
Jun 02, 2014 Jun 02, 2014

You said the leaves8 object is nested, but did niot indicate in what object it is nested.  If that code is on the main timeline, then you need to target the leaves8 thru the object it is in.  If it happens to be in the branch object and that is the name you gave it then you would use...

theleafbtn.addEventListener(MouseEvent.CLICK, thefunction);

function thefunction(event:MouseEvent):void {
    branch.leaves8.gotoAndPlay(1);
}

Translate
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
New Here ,
Jun 02, 2014 Jun 02, 2014

Forgive my ignorance.

I was probably not clear in my initial question.

I have 8 leaves that have been converted to symbols which are all individually animated. I selected all of the leaves and converted the group into a single movieclip that is labeled "leaves8".

On the main timeline it is a single frame. I am wanting to link to that single movieclip (leaves8) to play it.

I hope this makes sense.

Translate
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
LEGEND ,
Jun 02, 2014 Jun 02, 2014

If each of the leavesd is its own animation then you need to target each one of the leaves inside the leaves8 object.  If those are the only children inside the leaves8 object then you could do something like the following to get them to play...

function thefunction(event:MouseEvent):void {

     for(var i:int=0; i<leaves8.numChildren; i++){
          MovieClip(leaves8.getChildAt(i)).play();
     }
}


Translate
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
Guide ,
Jun 03, 2014 Jun 03, 2014
LATEST

I find it's simpler to use graphic symbols to handle this kind of synchronization than to manage multiple movie clips through code.

If you make each leaf into a Graphic symbol (you can do this in the instance properties for each, which won't affect the library symbol), then when the containing timeline plays, each leaf will play in synchronization. For example, if each leaf has 10 frames on the timeline, and leaves8 has 10 frames on the timeline, then as leaves8 plays frame 1, each leaf will also play frame 1, etc. Don't forget to put a stop() at the end of leaves8.

Translate
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