|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
class code placement
I wrote c++ programs before so I'm familiar with classes. My question is about the placement of the source code in flash. Let me explain:
I want to make a class, say creature, that I can assign to movieclips on the stage and have them make use of the class. for instance, say I have this code(which I don't know if it's correct). PHP Code:
Like I said, I want to have this code just once and then have the MCs make use of it. So, I figure I would do something like this. onClipEvent (load) { ball = new CREATURE(this); } onClipEvent (enterFrame) { ball.move(); } I figured I put the first code snnipet, the class definition, on the time line and then make a class intance on the particular object. This is not working though. What's the correct way to do this?
__________________
Some day I'll create a smart quote to put here. |
|
#2
|
|||
|
|||
|
depends on version really - 6 or 7??
version 6 (actionscript 1) PHP Code:
flash 2004 - same way of instantiating object, but you asign the class to the library item by right-click>>properties ![]() like that. hth ** admins, why are the lines double in the code????
__________________
beware of geeks bearing animated gifs. |
|
#3
|
||||
|
||||
|
Thanks for the reply, but all the abstraction is confusing me. For instance:
namespace.ClassName Which namespace do I use? Also, where is all this code placed, in the timeline, instance or part in the timeline and part in the instance? |
|
#4
|
|||
|
|||
|
PHP Code:
put that anywhere - you dont HAVE TO do this, it just makes things easier in the long run - its a workaround for namespaces in flash 6, dont need it in 7. essentially it creates an empty global object to store the classes in. since the namespace object is global it allows easy access from anywhere as well. so for com substitute your top level domain, and for domain your, um, domain name.... or call it oyster.orgy.from.hell if you must, it doesnt mattereverything up until PHP Code:
beneath that is the instantiation. i put each of my class scripts in the first frame of the main timeline on a different layer, with another layer(s) for instantiating the classes - this is done with each as a function; i then have another function called main() that calls those functions. finally i have a layer with a frame script of just PHP Code:
to start everything. everything willl ahve to be done in frame one of a movie unless you use #initclip - look it up in the manual and on the web. i though the abstraction was the way to go, rather than being asked where the 'varTracker' object was in the actionscript dictionary, and that i had commented quite clearly what each section did, sorry if that led to confusion. clearer now? or still like mud? Last edited by mushie : October 26th, 2003 at 08:58 AM. |
|
#5
|
||||
|
||||
|
still like mud. Thanks for the help, though. I guess I'm just not familiar enough, yet, with how flash handles objects. I will continue looking at some more examples.
|
|
#6
|
|||
|
|||
|
it is pretty ropey in flash; not helped by the fact that actionscript isnt exactly strict either.
heres a basic fla http://www.newmediascience.com/star.fla very simple class declaration and instantiation, using an event listener to call the object method. thats another problem, as movieclips dont have native event listeners - there is an undocumented (at least by macromedia) method for adding listeners to ANY objects called ASBroadcaster - have a look here, works great . ASBroadcaster ive just used an empty Object as a controller. hth |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > class code placement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|