Well, I dont really get the problem, but you can check out my motionfeeder Class if you want to
It does what you look for, and has some additional features as well...

----------------CLASS BELOW-------------------------------------
//****************************************************************************
//Copyright (C) 2005 SIR WILLIAM'S EAR, HB. All Rights Reserved.
//The following code is Developed at SIR WILLIAM'S EAR.
//Use it at your own risk, but include these comments if you do!
//SIR WILLIAM'S wishes you a pleasant afternoon, and reminds you, in a friendly manner, not //to forget to drink your tea at teatime, and to keep your hat on during wintertime.
//****************************************************************************
/**
* MotionFeeder can be used for various purposes when you want different objects * to listen to a repeatedly broadcasted event. Common tasks are Tweens or timer based * functions. "asInterval" flag denotes that an interval will be used as feeder. * This setting can be used to achieve timebased functionality in a simple way.
* When no "asInterval" flag is passed, a movieClip instance will be used as
* feeder, which will send the "setNextVal" event at the rate that the Movie is
* set to (default 12 frames/second)
* @author Eskil Janson
*/
import motion_fx.*;
dynamic class MotionFeeder {
private var mc:MovieClip;
private var intervalId:Number;
private static var _CLIPLEVEL:Number = -11111;
function MotionFeeder(asInterval:Boolean, intervalSpeed:Number, fastUpdate:Boolean) {
 this.init(asInterval, intervalSpeed, fastUpdate);
}
function init(asInterval:Boolean, intervalSpeed:Number, fastUpdate:Boolean):Void {
 AsBroadcaster.initialize(this);
 if (asInterval) {
  setIntervalSending(intervalSpeed, fastUpdate);
 } else {
  setMovieClipSending();
 }
}
function killListeningObjectsById(Id:String) {
 this.broadcastMessage("goSelfDestruct", Id);
}
function sendMessage() {
 //trace("sending ms");
 this.broadcastMessage("onSetNextVal");
}
function sendFastUpdateMessage() {
 this.broadcastMessage("onSetNextVal");
 updateAfterEvent();
}
function setMovieClipSending() {
 var clipAtCliplevel:MovieClip = this.getInstanceAtDepth(_CLIPLEVEL);
//trace("this.getInstanceAtDepth(_CLIPLEVEL) = "+this.getInstanceAtDepth(_CLIPLEVEL));
 if (typeof (clipAtCliplevel) != "undefined") {
trace("Motionfeeder cannot be initialized, a movieClip is occupying level -11111, check for errors");
 }
 mc = _level0.createEmptyMovieClip("$enterframe_source", _CLIPLEVEL);
 mc.reference = this;
 mc.onEnterFrame = function() {
  //trace("broadCasting");
  this.reference.sendMessage();
 };
 trace("-->>|| MotionFeeder sending with MovieClip at level "+_CLIPLEVEL);
}
function setIntervalSending(intervalSpeed:Number, fastUpdate:Boolean) {
 if (intervalId != null) {
trace("-->>|| clearing interval in Motion feeder, this should not have happened, check for errors!");
  clearInterval(intervalId);
 }
 if (fastUpdate) {
  intervalId = setInterval(this, "sendFastUpdateMessage", intervalSpeed);
 } else {
  intervalId = setInterval(this, "sendMessage", intervalSpeed);
 }
 trace("-->>|| MotionFeeder sending with Interval ");
}
}
-----------------------------------------------END OF CLASS----------------------------------- ----- Original Message ----- From: "Meinte van't Kruis" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Tuesday, December 13, 2005 10:18 AM
Subject: Re: [Flashcoders] Asbroadcaster and setinterval


both are correct, that isn't the problem.

the interval get's called properly

function fireInterval(){
       trace("A");
        this.broadcastMessage("onInterval",this.event);
}
^^ this traces "A" infinitely

But the message never gets broadcasted, so it enters the function, but it
doesn't broadcast the onInterval event.

Then I checked if it was any problem with the whole AsBroadcaster thing not
set up correctly, so I fired the event on a keydown event:

function keyDown(){
          this.broadcastMessage("onInterval",this.event);
}

this DOES broadcast the onInterval event..

so the interval function get's fired, but doesn't fire the onInterval event
for some mystical reason...
whereas another event(Key event in this case) CAN fire the onInterval event

I'm quite stuck on it actually :/

On 12/13/05, eskil janson <[EMAIL PROTECTED]> wrote:

Not shure if I got your problem right, but if you are using an object
where
the function exists which you want to
execute with your interval, the syntax should be something like :

intervalId = setInterval(this, "sendMessage", intervalSpeed);

where "this" is a reference to the object where the method ("sendMessage")
you are calling is located.
"intervalSpeed"  should be a number.

When Braodcasting the message, the first parameter is the name of the
method
you want to get called, and the second (and following) parameters are
optional parameters  to be passed on to the executing method.


/Eskil


----- Original Message -----
From: "Meinte van't Kruis" <[EMAIL PROTECTED]>
To: <Flashcoders@chattyfig.figleaf.com>
Sent: Monday, December 12, 2005 10:56 PM
Subject: [Flashcoders] Asbroadcaster and setinterval


Hello,

I'm trying something that might be obvious, but somehow isn't. What I'm
trying to do is broadcasting a message on a setinterval basis.

I've set up my events broadcaster class and it worked quite well.
The problem i had with it was that it extended MovieClip.. The only reason
for this was the onEnterFrame function, seemed a waste.

I came up with this to replace the onEnterframe and subsequently have the
eventbroadcaster class extend Object instead of MovieClip:

this.intervalID=setInterval(this.fireInterval,interval); <---- in the
class'
constructor

function fireInterval(){
        //_root.log.log(this._listeners);
        this.broadcastMessage("onInterval",this.event);
}

Now, i've traced within the fireInterval function, and it works fine.
Problem is, the listeners never get the onInterval event broadcasted to
them.
When i do this(it also listens to key events):

function keyDown(){
           this.broadcastMessage("onInterval",this.event);
}

it DOES work... So i'm quite stumped here,

first of all the fireInterval function gets executed, but the listeners
never hear it and
secondly, when I have a key event broadcast the event, the listeners DO
hear
it...

What's the problem here? Don't AsBroadcaster and setInterval like each
other?

thanks,
Meinte
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to