Solved

Movie Clip with Close button won't stop looping

Posted on 2011-09-25
7
656 Views
Last Modified: 2012-05-12
Hi EE

I have a Flash CS5.5 file with 1 frame in the timeline. In that frame I have a button which when clicked opens a movie clip. The movie clip is a 24-frame animation (it's a motion tween), and has a Close button on the Frame 24. However, when I test the FLA, the movie clip loops and I get the error:

TypeError: Error #1010: A term is undefined and has no properties.
      at scrCustomerMaint_fla::MainTimeline/frame1()

My code is:

modAnimate.visible = false;
btnCustCode.addEventListener(MouseEvent.CLICK, showPopup);
function showPopup(event:MouseEvent):void
{
	modAnimate.visible = true;
}

modAnimate.btnClose.addEventListener(MouseEvent.CLICK, hidePopup);
function hidePopup(event:MouseEvent):void
{
	modAnimate.visible = false;
}

Open in new window


Debug says the problem is on the "modAnimate.btnClose" line. I guess it's because btnClose isn't available at that point, but I don't know how to fix the problem. I've tried adding a stop() function to Frame 24 of the movie clip but that just throws up more errors. Can anyone please help?

Incidentally, if I use a similar movie clip - one that has no motion tween - the above scenario works perfectly, i.e. main timeline button opens the movie clip, and the movie clip's Close button closes the movie clip.

TIA
0
Comment
Question by:cmattar
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 36597057
The issue here is that when you load a MovieClip and want to access a property (btnClose in this case), the property must be defined in the first frame so it can be used.

Sooo, the fix is rather simple, btnClose must exist in the first frame (and throughout the timeline). You can extend the frame it appears in so it's from frame 1 to 24 and set it invisible via code (btnClose.visible = false;) on frame 1 and visible again on frame 24 (btnClose.visible = true;).

You could also simply make it a new keyFrame and set its alpha to 0 in the timeline.

I'm not sure if I'm being clear over here, heh. If I'm not I can provide a sample.

Good luck,

-V
0
 

Author Comment

by:cmattar
ID: 36597163
Thanks for responding Vulturous, however either I'm not understanding you or I've not explained the issue correctly.

I've got a button on the main timeline which opens the movieclip - the movieclip is the object that's looping. Using your suggestion, I can now have btnClose appearing thru the whole 24 frames (thanks for that!), so I can click that in the movieclip to stop it - but the rest of the clip loops. Putting a stop() on frame 24 doesn't help as the movieclip then just jumps to the end of its timeline, i.e. no animation.

I'd upload the FLA but EE won't allow it - says that .xlf is not an allowed extension. I'm assuming that the .xlf referred to is the ActionScript part of the FLA...?
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 36597192
Can you try exporting the file to Flash CS4 or Flash CS5? (should be a *.fla, not *.xlf).

And yeah, I must have not explained myself all too well.

-V
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:cmattar
ID: 36597239
No problem - CS4 uploads seem to behave themselves. You'll see I've implemented your suggestion about alpha on the btnClose within the movieclip. Thanks for taking a look.
ButtonTest-CS4.fla
0
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 36597275
Alright so what happened here... is that I assumed that you were loading the modAnimate MovieClip on runtime, but you already have it in the timeline and just call it.

The fix here is to go ahead and place the stop(); on frame 24 as before (when the animation didn't appear) but also modifying the code a bit to prevent it from animating before.

Code on the main timeline:

 
modAnimate.visible = false;
modAnimate.gotoAndStop(1);
btnOpen.addEventListener(MouseEvent.CLICK, showPopup);
function showPopup(event:MouseEvent):void
{
	modAnimate.visible = true;
	modAnimate.play();
}

modAnimate.btnClose.addEventListener(MouseEvent.CLICK, hidePopup);
function hidePopup(event:MouseEvent):void
{
	modAnimate.visible = false;
	modAnimate.gotoAndStop(1);
}

Open in new window


What made the popup loop or not show animation when clicked on was that it was present on the timeline, so when the swf opened, both timelines started to run (the main timeline, 1 frame, and the modAnimation timeline (24 frames)) so when you clicked on it, that MovieClip was already animating.

Sooo I added a bunch of stops (or gotoAndStop) to ensure that when you click on it, it hasn't played and shows from the first frame. And when you close it, it goes back to the first frame.

Again, I'm not sure if I'm being clear, seems that I'm writing contrived stuff today for no apparent reason haha. If this ain't clear (quite possible) I can upload your corrected fla, clear my mind a bit (get some rest and stuff) and write something better tomorrow :P.

Good luck!

-V
0
 

Author Comment

by:cmattar
ID: 36597292
It worked! Never would've figured this out myself. I can also understand the logic of the solution, so thanks for taking the time to explain that. Thanks heaps :-)
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 36597332
I'm glad I was able to help out :D

-V
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SWF won't scale? 4 523
Adobe indesign suite cs5.5   How to enable "indesign" capability? 2 199
Google Chrome pepflashplayer.dll 8 133
How to block online streaming via TMG2010 ? 2 132
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now