Game graphics/animation questions
I'm new to Flash, so I am *not* aware of some seemingly obvious things, such as the existence of certain methods or the way that .fla interacts with code. Please keep this in mind when giving explanations ![]()
I was reading a tutorial and it said that you can reference the symbols directly just with the symbol name. Is it possible to do this without applying actions but rather by using an external .as file? I tried, but I got lots of undefined errors even though I import the stage class and so on. This is the site that I was looking at: http://www.tutcity.com/view/keyboard-controls-in-as3.19742.html. However, it seems to require adding actions in flash. I got it working when using the Flash actions as suggested, but I'd like to have the code in the .as files only, rather than relying on Flash actions, for more control. I don't know how to get the .as file to recognize stage, so I get the following errors:
1120: Access of undefined property stage.
1120: Access of undefined property keyHit.
Do I have to instantiate the stage or something? Shouldn't the .fla file know what the stage is? I've tried import flash.display.* too and it didn't work. This is my code.
package code
{
import flash.events.*;
import flash.display.Stage;
import flash.display.MovieClip;
import flash.ui.Keyboard;
public class Paradox extends MovieClip
{
function keyHit(event:KeyboardEvent):void
{
var enemySpeed:uint=5;
switch (event.keyCode)
{
case Keyboard.RIGHT :
MechDragon.x+=enemySpeed;
break;
case Keyboard.LEFT :
MechDragon.x-=enemySpeed;
break;
case Keyboard.UP :
MechDragon.y-=enemySpeed;
break;
case Keyboard.DOWN :
MechDragon.y+=enemySpeed;
break;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);
}
}
I don't understand the relationship between the .fla file and the .as file as far as animation goes. Is there a redraw command, or a next frame command or something? Also, is there a command to get the frame? I want to be saving a bunch of frames to a list or something (gonna do some time manipulation stuff). I also want to be able to change the graphics depending upon what happens. For example, if the character moves left, switch to the moving left sprite. If the character moves up, switch to the moving up sprite, etc. But I want it to be linked to the same object, just have the image change. Can I do this or must I make lots of objects and mess around with some graphics switches?