Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-03-2009, 04:20 PM   #1
britsky
Registered User
 
Join Date: Oct 2009
Posts: 2
Question Can ActionScript detect when a Motion Tween ends or begins?

I also posted this in the Newbie section last week, but didn't get a response there yet.

Project:
Reading text from XML document
Text scrolls up, pauses, then automatically scrolls up and off the screen
Text content changes to the next node.

Scene Level:
I have a movie clip named "symbol headline" (see attached screenshot)

Within the Movie Clip:
I have 2 dynamic text boxes: headlineText and contentText (see attached screenshot)

Action Script:
ActionScript Code:
// Import flash libraries import flash.events.Event; import flash.events.MouseEvent; import flash.display.MovieClip; import flash.display.SimpleButton; import flash.xml.*; import flash.net.*; // Declare variable to hold XML and load the XML document var vendorFlash_xml:XML = new XML(); var XML_URL:String = "VendorFlash.xml"; var myXMLURL:URLRequest = new URLRequest(XML_URL); var myLoader:URLLoader = new URLLoader(myXMLURL); myLoader.addEventListener("complete", xmlLoaded); // This function is run when the load of the XML is complete function xmlLoaded(event:Event):void {     vendorFlash_xml = XML(myLoader.data);     var i:int = 1; //Starting at 1 because we'll be displaying the first node manually     var item_count:int = vendorFlash_xml.item.length();     var pattern:RegExp = /\\n/gi; //We'll use \n in the XML to denote a newline.  This pattern is used below to insert a \r     var contentString:String //Needed for string replace function         var timer:Timer = new Timer(6000,0); //Timer(milliseconds, repeat count[0 for infinite])     timer.addEventListener(TimerEvent.TIMER, timerHandler);     timer.start();         // Display the first node so there's not a delay.     headlineText.text=vendorFlash_xml.item[0].headline.text();     contentString=vendorFlash_xml.item[0].content.text();     contentText.text=contentString.replace(pattern,"\r");         function timerHandler(event:TimerEvent):void {         headlineText.text=vendorFlash_xml.item[i].headline.text();         contentString=vendorFlash_xml.item[i].content.text();         contentText.text=contentString.replace(pattern,"\r");         i++;         if (i == item_count) {             i = 0;         }     } }

The Problem:
Everything works GREAT except there is a slight difference between the TIMER in the ActionScript and the frames in the GUI. That means that after 3 or 4 iterations, the text starts changing before the motion tween is done.

My Idea:
Instead of using a timer in my ActionScript, can I create and Event Listener that listens for when the movie clip starts to replay? If so, HOW ?

This is my first ActionScript project, and I've exhausted my Google abilities to figure out this last hurdle.

Many thanks, and God bless!
-Jeff
Attached Thumbnails
Click image for larger version

Name:	vf_scene.jpg
Views:	105
Size:	126.7 KB
ID:	32803   Click image for larger version

Name:	vf_text.jpg
Views:	72
Size:	123.5 KB
ID:	32804  
britsky is offline   Reply With Quote
Old 11-03-2009, 04:53 PM   #2
midnit
Registered User
 
Join Date: Oct 2009
Location: Washington, DC
Posts: 34
Send a message via AIM to midnit
Default

You can create an Event Listener to detect when a Motion Tween has finished using the Tween Event class, however, I don't know if the listener will work with timeline tweens.

You may or may not need to create your tween using the Tween Class (or TweenLite or Tweener)

Hope that helps!

Edit: If I get some free time here at work, I can write an example of how this is done, if the Adobe Language Reference page doesn't have one ( I didn't bother to check )
midnit is offline   Reply With Quote
Old 11-03-2009, 05:01 PM   #3
krayzeebean
Senior Member
 
Join Date: Feb 2006
Posts: 682
Default

On the last frame of your tween have it dispatch an event so you know it's done. dispatchEvent(new Event("AnimationComplete", true));
krayzeebean is offline   Reply With Quote
Old 11-03-2009, 05:17 PM   #4
CMYMatt
Member
 
Join Date: Aug 2009
Posts: 55
Default

I would suggest using TweenLite.
Then using the "onComplete:someFunction;".
You will avoid being garbage collected too.

What krayzeebean said would also work.

Good luck.
CMYMatt is offline   Reply With Quote
Old 11-03-2009, 05:30 PM   #5
omega_platypus
Registered User
 
Join Date: Oct 2009
Posts: 3
Default

For britsky:


MovieClips do not dispatch any event when they start to replay. However, you can use the currentFrame and totalFrame of the movie to determine when it hits the first frame. For example:

Code:
/*m refers to the movieclip we want to listen for. If this code is on the timeline we want to check, just leave it set to 'this' */
var m:MovieClip=this;
/*Since the playhead will reach frame 1 before it ever loops, we want to be sure it goes around at least once before saying it has restarted. If you don't want this check, set looped to true right here */
var looped:Boolean=false; 

m.addEventListener(Event.ENTER_FRAME,onEnterFrame);

function onEnterFrame(e:Event):void
{
    looped=true;
    if(m.currentFrame == 1)
    {
         //Then the movieclip has restarted from the first frame. Act accordingly.
    }
}
Let me know if this helps!

Last edited by omega_platypus; 11-03-2009 at 05:32 PM. Reason: for britsky
omega_platypus is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:35 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.