04-10-2008, 05:11 PM
|
#1
|
|
Snarfarious
Join Date: Jan 2002
Posts: 215
|
How to add ENTER_FRAME events to a class that is not a display object?
I have a class that manages a group of movie clips. This class is not a display object, but i want it to receive ENTER_FRAME so it can update the objects it manages.
I try to add a listener but I get the error Call to a possibly undefined method addEventListener. I Assume this is because the object is not a display object.
|
|
|
04-10-2008, 05:15 PM
|
#2
|
|
Feathers
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
|
Listen for the ENTER_FRAME event from one of the "group of movie clips" you're managing.
__________________
Josh Tynjala | Feathers
|
|
|
04-10-2008, 05:21 PM
|
#3
|
|
Senior Member
Join Date: Nov 2007
Posts: 110
|
most likely the class managing them is not derived from the correct class for this to work. the base class in flash is Sprite, i suggest using this.
|
|
|
04-10-2008, 05:44 PM
|
#4
|
|
Snarfarious
Join Date: Jan 2002
Posts: 215
|
Thanks for the replies. I'm working on a simple 3d class. It will transform objects on the stage based on x, y and z values. The new system for depth makes it tougher to manager z depth in AS3.
I have built a singleton class whose purpose is manage depths and transforms for all 3d clips. This class doesn't need to be displayed so it doesn't seem correct to make it a sprite or a MovieClip. Then again maybe I could make it a Sprite and not add it to any display list.
I also have the problem of setting the depths of 3d objects in different display lists. At this point I'm thinking it might be best to create a 3d display container. 3d objects would be added to this container and it would manager their depths. In this way the manager would be the container and it would be a display object which solves the ENTER_FRAME problem and the problem of different objects in different displaylists.
|
|
|
04-10-2008, 05:48 PM
|
#5
|
|
Senior Member
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,780
|
addEventListener is a function available only to classes that inherit from "EventDispatcher". The problem is Event.ENTER_FRAME is only dispatched by display objects though (all display objects inherit from EventDispatcher).
If all I need is to receive the ENTER_FRAME event I stick a shape in my class (very light weight) or use one of the display objects that are part of the class (if any). If I need the little bugger to dispatch its own events or listen for events that aren't displayobject specific I then implement IEventDispatcher or inherit from EventDispatcher.
__________________
www.lordofduct.com - come read my blog!
If you want to know how to program, take a math class, take a lot of math classes!
|
|
|
04-10-2008, 06:27 PM
|
#6
|
|
Snarfarious
Join Date: Jan 2002
Posts: 215
|
That's interesting information. I tried to extend EventDispatcher, but it didn't work with ENTER_FRAME.
|
|
|
04-10-2008, 06:32 PM
|
#7
|
|
Senior Member
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,780
|
Quote:
Originally Posted by soggybag
That's interesting information. I tried to extend EventDispatcher, but it didn't work with ENTER_FRAME.
|
I said that, EventDispatcher gives you access to adding event listeners and all that good stuff. But EventDispatchers never dispatch the event ENTER_FRAME.
DisplayObjects do though, hence the shape.
__________________
www.lordofduct.com - come read my blog!
If you want to know how to program, take a math class, take a lot of math classes!
|
|
|
04-10-2008, 06:35 PM
|
#8
|
|
Senior Member
Join Date: Nov 2007
Posts: 529
|
that's cute, you inherit from EventDispatcher and then create a new shape to listen to just for enterFrame?
That's the kind of thing that an actionscript programmer would chuckle about and any other kind of programmer would slap his forehead
an obvious alternative, btw, is to pass a reference to the stage & use that =P
|
|
|
04-10-2008, 06:46 PM
|
#9
|
|
Senior Member
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,780
|
Quote:
Originally Posted by jaga
that's cute, you inherit from EventDispatcher and then create a new shape to listen to just for enterFrame?
That's the kind of thing that an actionscript programmer would chuckle about and any other kind of programmer would slap his forehead
an obvious alternative, btw, is to pass a reference to the stage & use that =P
|
I didn't say I inherit and then create...
I said I usually inherit from if I want to be able to dispatch events. I use a shape if I only need to listen for ENTER_FRAME, and I don't inherit from. Maybe I didn't describe it very well. And yeah, you can also pass a reference to some object (like the stage) that dispatches that event as well. But sometimes I don't have that choice (as I said in my first post about attatching to some object that already dispatches the event).
__________________
www.lordofduct.com - come read my blog!
If you want to know how to program, take a math class, take a lot of math classes!
|
|
|
04-10-2008, 06:57 PM
|
#10
|
|
Senior Member
Join Date: Nov 2007
Posts: 529
|
I wasn't criticising, in fact the opposite, I just find it amusing that that is one solution
can always create a static reference to the stage in your docu class tho.. but your solution works all the same
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 03:30 AM.
///
|
|