Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
What is the code you are using that you are having trouble with? Do you get any error messages?
Copy link to clipboard
Copied
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()
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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();
}
}
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now