Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 04-10-2008, 05:11 PM   #1
soggybag
Snarfarious
 
Join Date: Jan 2002
Posts: 215
Default 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.
soggybag is offline   Reply With Quote
Old 04-10-2008, 05:15 PM   #2
dr_zeus
Feathers
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,999
Default

Listen for the ENTER_FRAME event from one of the "group of movie clips" you're managing.
__________________
Josh Tynjala | Feathers
dr_zeus is offline   Reply With Quote
Old 04-10-2008, 05:21 PM   #3
pelkin000
Senior Member
 
Join Date: Nov 2007
Posts: 110
Default

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.
pelkin000 is offline   Reply With Quote
Old 04-10-2008, 05:44 PM   #4
soggybag
Snarfarious
 
Join Date: Jan 2002
Posts: 215
Default

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.
soggybag is offline   Reply With Quote
Old 04-10-2008, 05:48 PM   #5
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

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!
lordofduct is offline   Reply With Quote
Old 04-10-2008, 06:27 PM   #6
soggybag
Snarfarious
 
Join Date: Jan 2002
Posts: 215
Default

That's interesting information. I tried to extend EventDispatcher, but it didn't work with ENTER_FRAME.
soggybag is offline   Reply With Quote
Old 04-10-2008, 06:32 PM   #7
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by soggybag View Post
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!
lordofduct is offline   Reply With Quote
Old 04-10-2008, 06:35 PM   #8
jaga
Senior Member
 
Join Date: Nov 2007
Posts: 529
Default

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
jaga is offline   Reply With Quote
Old 04-10-2008, 06:46 PM   #9
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by jaga View Post
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!
lordofduct is offline   Reply With Quote
Old 04-10-2008, 06:57 PM   #10
jaga
Senior Member
 
Join Date: Nov 2007
Posts: 529
Default

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
jaga 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
Loading a swf created using document class gives error #1009 charlieFlash ActionScript 3.0 6 07-08-2010 08:59 PM
Issues with events in custom class box86rowh ActionScript 3.0 1 08-29-2007 09:35 PM
Accessing display object from another class aphex ActionScript 3.0 2 07-23-2007 05:55 PM
dispatchEvent from a class that extends Object? DrElvisToad ActionScript 3.0 6 07-06-2007 05:05 PM
card game: designing Deck class and good OOP? pigpen Gaming and Game Development 1 11-26-2002 11:41 AM


All times are GMT. The time now is 01:40 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.