View Full Version : moveiclip confusion
hakukaji
August 31st, 2007, 01:00 PM
ok im walking into cs3 and as3 fresh, as in i really don't have any as2 exp. I am however a very seasoned programmer and use OOP techiniques daily. I just think i need a little clarification, that I can't seem to locate any where.
Here's what I currently have and what i want to do.
I have a small png file that i put in the library, used linkage to give it a class name and then export for ActionScript.
I then created a class called Player that extends MovieClip and I create an instance of my new library created class in there and use addChild
then in my "main" fla I create a new instance of player and use stage.addChild(player) and it i can see my mc.
Is this the correct way of doing it, or am i adding steps.
Ok, so now i wanted to make this icon move around using the arrow keys, if I use the addEventListener in the Player constructor to point to a class method, it does not work. It seems I have to put the addEventListener with the stage.
So im sure that was painful for some to read, but I would appreciate any feedback.
Thanks, and senocular , WOW! impressive show of support for this community.
BradLee
August 31st, 2007, 01:22 PM
I use the addEventListener in the Player constructor to point to a class method, it does not work. It seems I have to put the addEventListener with the stage.
Actually it most likely doesn't work because you can't access the stage from an object that isn't in the display list. When you object is instantiated and the constructor is called you haven't yet done an addChild() and added it to the display list.
You probably want add your listeners to the stage, otherwise keyboard events won't happen like you expect.
So, you need to listen for the ADDED_TO_STAGE event in your Player class. Then in the event handler for ADDED_TO_STAGE you can add your key listeners to the stage.
senocular
August 31st, 2007, 01:25 PM
You're on track. Though techincally not "wrong", its best if you do not add objects directly to stage. You should really be working within root or just use "addChild(player)" in your main timeline since your main timeline is root - or any other instance embedded within.
Also, in case you are adding library assets to others manually (through the authoring environment and not through code) just know that exporting for ActionScript then is not required.
For key movements, you would need to use stage, though, more specifically its about what object has focus. Since that object will (should) always be in the active display list, you will always get key events propagating through to stage so using stage is always a safe bet for aquiring keyboard events.
:beam:
hakukaji
August 31st, 2007, 04:39 PM
You're on track. Though techincally not "wrong", its best if you do not add objects directly to stage. You should really be working within root or just use "addChild(player)" in your main timeline since your main timeline is root - or any other instance embedded within.
Also, in case you are adding library assets to others manually (through the authoring environment and not through code) just know that exporting for ActionScript then is not required.
For key movements, you would need to use stage, though, more specifically its about what object has focus. Since that object will (should) always be in the active display list, you will always get key events propagating through to stage so using stage is always a safe bet for aquiring keyboard events.
:beam:
Yeah i knew this was going to be a good forum, I'm still trying to wrap my head around the basics of flash terminology. What i've been doing is creating 1 frame and applying all my actions in there, and putting my classes in respective packages, so how do i work within root and if im not really using frames should i be coding in something like eclipse(That i use daily for php work)?
senocular
August 31st, 2007, 04:51 PM
Any way you look at it, you're using frames, even if only the first frame (1 frame) as a context in which to contain your visual elements. That does not dictate your use of root. The main timeline, aka root, aka application class, aka document class should always be the "main" of your application. It's constructor is the entry point for code execution in your SWF. All content specific to that SWF should be contained within - this all independant of the coding/authoring environment.
You can code AS3 in Eclipse if you want. And really, if you're not drawing anything within Flash by hand (only using script) then it may be your tool of choice. However, Flash makes working with other assets and vector drawings which can be made in the authoring environment much easier.
Personally, when I'm working with Flash for any substantial project, I will keep pretty much all code in external classes (the only exceptions would include stop() commands on animated assets which have no class association). Simpler projects I will keep in the timeline just because its easier - assuming the code can be managed ok there without too much difficulty (not too excessive).
... At the same time, you can use Flash for your visuals and just code your external AS files in Eclipse. That actually would probably be ideal (and come to think of it I rarely if ever use Flash authoring for my external AS files)
hakukaji
August 31st, 2007, 05:52 PM
Any way you look at it, you're using frames, even if only the first frame (1 frame) as a context in which to contain your visual elements. That does not dictate your use of root. The main timeline, aka root, aka application class, aka document class should always be the "main" of your application. It's constructor is the entry point for code execution in your SWF. All content specific to that SWF should be contained within - this all independant of the coding/authoring environment.
You can code AS3 in Eclipse if you want. And really, if you're not drawing anything within Flash by hand (only using script) then it may be your tool of choice. However, Flash makes working with other assets and vector drawings which can be made in the authoring environment much easier.
Personally, when I'm working with Flash for any substantial project, I will keep pretty much all code in external classes (the only exceptions would include stop() commands on animated assets which have no class association). Simpler projects I will keep in the timeline just because its easier - assuming the code can be managed ok there without too much difficulty (not too excessive).
... At the same time, you can use Flash for your visuals and just code your external AS files in Eclipse. That actually would probably be ideal (and come to think of it I rarely if ever use Flash authoring for my external AS files)
awesome, so i take it there is a "main" class just like in java and c#? and i assume that's the first frame. Also since i'm gonna move on over to eclipse , how would i utilize something like a png as a movieclip, the only way i know to do this now is 'Convert to Symbol' does that create a class that extends movieclip and then inside the constructor loads the png?
BradLee
August 31st, 2007, 05:59 PM
The main class in flash is called the Document class. The Document class is the root. It has the movie timeline and all that in it.
To load things without converting them to symbols and putting them in the library (you'd have to do that in Flash not Eclipse) use the Loader class.
I'll leave all the more technical explanations to Senocular...
hakukaji
August 31st, 2007, 07:18 PM
ok i just downloaded the flex sdk, is this how i should use eclipse and as3, or is there a better way? and TheSpork, nice FIF quote!
senocular
August 31st, 2007, 07:22 PM
You would use the Flex SDK... or, I think you can buy a Flex plugin for Eclipse as well, but the SDK is free.
From there, I am not sure of the details of setting up the compiler, but I'm sure anyone semi-familiar with Flex can figure it out. There's probably some open source development utilities for this as well. osflash.org is a good place to look for that.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.