Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-27-2008, 04:58 PM   #1
pixielex
Member
 
Join Date: Aug 2006
Posts: 92
Question custom event handler for a timer event?

I understand how to create custom events in order to pass parameters to a function being called by an event listener. I can get this to work fine if the event is being dispatched within my own code. However, I don't get how to do this if the event is a built-in event being dispatched by a Flash object.

Specifically, I need to call a function and pass it parameters when a timer ends. I don't know how to change the information being sent by the Timer because it is a native Flash class rather than something I'm writing. Can someone please clarify how to do this?
pixielex is offline   Reply With Quote
Old 02-27-2008, 05:19 PM   #2
xwielder
Senior Member
 
Join Date: Aug 2007
Location: NE Ohio
Posts: 520
Send a message via AIM to xwielder
Default

If you're referring to something like:
ActionScript Code:
mcAlphaInTween.addEventListener (TweenEvent.MOTION_FINISH, thisFunction, thisPassedVar); function thisFunction (event:TweenEvent, thisPassedVar):void {     // blah blah blah }

Then no, you cannot do this.
xwielder is offline   Reply With Quote
Old 02-27-2008, 05:22 PM   #3
pixielex
Member
 
Join Date: Aug 2006
Posts: 92
Default

So there's no way to customize that event to pass a parameter through it? I mean, if it's an event I'm dispatching, I just create a custom event class and it's fine. I find it hard to believe that there's no equivalent way to deal with events dispatched within native Flash objects....?
pixielex is offline   Reply With Quote
Old 02-27-2008, 08:04 PM   #4
pixielex
Member
 
Join Date: Aug 2006
Posts: 92
Default

Anyone?
pixielex is offline   Reply With Quote
Old 02-28-2008, 01:46 AM   #5
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

What kind of parameter do you want to pass through it?

Is it a parameter that is part of the object running the event? If so just use:

function thisFunction (e:ThisEvent):void {
e.currentTarget.property... blah blah;
}

This would work for say you have a TimerEvent attached to some group of timers... then you could set the delay with:
e.currentTarget.delay = 5000;

so if this function hit under the TimerEvent.TIMER_COMPLETE event then the timer that completed would have its delay reset.

Now if you want to extend the event so that there are new events to call on top of the preexisting ones... then just create a new class that inherits (extends in AS3) the event class you are playing with. It is a new custom event that has all the abilities of the event you inherited from plus any new functions and properties you add to it.

Last edited by lordofduct; 02-28-2008 at 01:48 AM.
lordofduct is offline   Reply With Quote
Old 03-27-2008, 12:06 PM   #6
darth
Senior Member
 
darth's Avatar
 
Join Date: Dec 2003
Location: Estonia
Posts: 273
Default

in AS2 with setTimeout and setInterval you could send parameters, but not with Timer AS3?
The only way is to make variable(s) of the class where the functions are running from and store-fetch like that?
darth is offline   Reply With Quote
Old 03-27-2008, 12:24 PM   #7
creynders
flash veteran
 
creynders's Avatar
 
Join Date: May 2005
Location: Belgium
Posts: 914
Default

Quote:
Originally Posted by darth View Post
in AS2 with setTimeout and setInterval you could send parameters, but not with Timer AS3?
The only way is to make variable(s) of the class where the functions are running from and store-fetch like that?
You still have setTimeout and setInterval in AS3. They are no longer global functions though. They're a part of the flash.utils package.
creynders is offline   Reply With Quote
Old 03-27-2008, 12:30 PM   #8
darth
Senior Member
 
darth's Avatar
 
Join Date: Dec 2003
Location: Estonia
Posts: 273
Default

Ok thanks! So this means no function parameters with Timer. Case closed?
darth is offline   Reply With Quote
Old 07-02-2008, 09:49 PM   #9
b0jangles
Registered User
 
Join Date: Jul 2008
Posts: 3
Default

Quote:
Originally Posted by darth View Post
Ok thanks! So this means no function parameters with Timer. Case closed?

You can pass parameters to a callback function with Timer. You just have to make your own Class that extends Timer. You can see how to do it here:

http://gersic.com/blog.php?id=49

Tom

Last edited by b0jangles; 07-02-2008 at 09:51 PM.
b0jangles is offline   Reply With Quote
Old 07-02-2008, 11:08 PM   #10
matlevy
Registered User
 
Join Date: Jul 2008
Posts: 14
Default

To do this you will need to create an instance of the Timer class and add an event listener that maps to a function taking the event as a parameter of a TimerEvent (or super class).

As an example :

ActionScript Code:
var foo : Timer = new Timer(1000,1); foo.addEventListener(TimerEvent.TIMER, myFunction); function myFunction(e:TimerEvent):void {   Alert.show('Hello'); }

For more information on the Timer class read here. You can also find details in the flash documentation. The class and package path is under flash.utils.Timer
matlevy 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom event handlers - triggering event listeners on other objects dansumption ActionScript 3.0 2 02-16-2008 10:58 PM
Creating new event handler for MC Jayme65 ActionScript 2.0 2 09-09-2006 04:15 PM
"Unsetting" an event handler? TrentD ActionScript 2.0 2 06-01-2006 04:51 PM
Removing event handler Bjorn Johnson ActionScript 1.0 (and below) 2 03-31-2004 11:17 PM
onLoad Event Handler mundi74 ActionScript 1.0 (and below) 1 07-12-2003 08:40 PM


All times are GMT. The time now is 11:26 AM.

///
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.