PDA

View Full Version : Classes > onEnterFrame doesnt work ??



maverick_xj
May 7th, 2005, 05:34 AM
Hey

disclaimer: have been working too hard, too long - so if this is as simple as abc , please excuse ... but do help :(
This is a simplified vesion of the problem :


I made a class named "fo" :


class fo {
function onEnterFrame(){
trace("HERE");
}
}

the swf file calling this file had:


var tr:fo = new fo();

Now when i run this swf ... it traces nothing ... ????

( The as file is named fo.as and is in the same foledr as the swf file )

kode
May 7th, 2005, 01:25 PM
The onEnterFrame event handler is for movie clips only, you'd need to use some unorthodox methods to make it work for other objects. ;)

class fo {
public function fo() {
if (!_level0.$oefc) {
_level0.createEmptyMovieClip("$oefc", 9876543210);
_level0.$oefc.onEnterFrame = function() {
MovieClip.broadcastMessage("onEnterFrame");
};
AsBroadcaster.initialize(MovieClip);
}
MovieClip.addListener(this);
}
public function onEnterFrame():Void {
trace("HERE");
}
}

maverick_xj
May 7th, 2005, 02:12 PM
Thanx for the help :)

senocular
May 7th, 2005, 02:42 PM
note that MX04 comes with the OnEnterFrameBeacon class which will allow your generic objects to recieve the onEnterFrame event.

maverick_xj
May 7th, 2005, 02:49 PM
note that MX04 comes with the OnEnterFrameBeacon class which will allow your generic objects to recieve the onEnterFrame event.

Thanx for the info :) , but frankly i've never come across " onEnterFrameBeacon ".
Could you direct me to some place I could get more info on this class ?

senocular
May 7th, 2005, 02:52 PM
all you have to do is call

mx.transitions.OnEnterFrameBeacon.init();
and that will enable the MovieClip object to have listeners. You only have to do this once for your entire movie. Then, for an object to recieve onEnterFrame use

MovieClip.addListener(myObject);

maverick_xj
May 7th, 2005, 03:07 PM
all you have to do is call

mx.transitions.OnEnterFrameBeacon.init();
and that will enable the MovieClip object to have listeners. You only have to do this once for your entire movie. Then, for an object to recieve onEnterFrame use

MovieClip.addListener(myObject);

thanx for the info :D

what about those cases where i am creating my own movie clips in the class ?
e.g.
in the attached file, in the class tDescramble i am creating a MovieClip tDisplay. how do i add this listener to the mentioned class ?

kode
May 7th, 2005, 06:21 PM
note that MX04 comes with the OnEnterFrameBeacon class which will allow your generic objects to recieve the onEnterFrame event.
Hey! That's certainly much easier. Since I've never used those classes (I rather script my own stuff), I didn't know about it. :P

senocular
May 7th, 2005, 06:34 PM
its basically what you had posted before :D

maverick_xj
May 7th, 2005, 06:56 PM
its basically what you had posted before :D

Hey , just opened the onEnterFrameBeacon class and looked at the coding ...
figured it out ...
But thanx a ton for the info :D

I "DEFINITELY" needed that 5 hour of sleep !!!

I agree its basically what encoder had suggested ...
" just what the doctor had ordered" .. eh ?
:D

kode
May 7th, 2005, 11:31 PM
its basically what you had posted before :D
Yeah, I know... ;)

What I meant is that it's easier for beginners that don't know what they're doing (no offense to anyone), since they can just call a couple of methods and get the same results.