Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-15-2010, 06:11 AM   #1
Jigrael
Registered User
 
Join Date: Nov 2010
Posts: 2
Default [AS3] Movie clip doesnt play

Hi. This is my first try to program a game in flash and Im having trouble making my character move. I want to work with class files for the player, to have all the code for the player in that class. So I put the movement code there and it moves, but I cant make it play its animations, like when moving, the player movie clip, should play the walking animation, but it doesnt. Pls help me.

Heres the code for the Engine class asociated to the stage and the Actor class asociated to the player:

ActionScript Code:
package {     import flash.display.MovieClip;     public class Engine extends MovieClip     {         public function Engine():void         {             var player:Player = new Player(stage);             addChild(player);               }     } }

ActionScript Code:
package {     import flash.display.MovieClip;     import flash.display.Stage;     import flash.events.KeyboardEvent;     import flash.events.Event;     import flash.ui.Keyboard;     public class Player extends MovieClip     {         private var stageRef:Stage;         var vel:int = 5;         private var _movingUp:Boolean = false;         private var _movingDown:Boolean = false;         private var _movingLeft:Boolean = false;         private var _movingRight:Boolean = false;         public function Player(stageRef:Stage):void         {             this.stageRef = stageRef;             stageRef.addEventListener(KeyboardEvent.KEY_UP,Release);             stageRef.addEventListener(KeyboardEvent.KEY_DOWN,Press);             addEventListener(Event.ENTER_FRAME,Loop);             x = stageRef.stageWidth / 2;             y = stageRef.stageHeight / 2;             trace("Inst");             trace(this.name);             gotoAndStop('still');         }         public function Loop(e:Event):void         {             // Move up, down, left, or right             if (_movingLeft && ! _movingRight)             {                 this.gotoAndStop('walking');                 this.x -=  vel;                 this.scaleX = 1;             }             else if (!_movingLeft && _movingRight)             {                 this.gotoAndStop('walking');                 this.x +=  vel;                 this.scaleX = -1;             }             else             {                 this.gotoAndStop('still');             }         }         public function Press(event:KeyboardEvent):void         {             switch ( event.keyCode )             {                 case Keyboard.UP :                     _movingUp = true;                     break;                 case Keyboard.DOWN :                     _movingDown = true;                     break;                 case Keyboard.LEFT :                     _movingLeft = true;                     break;                 case Keyboard.RIGHT :                     _movingRight = true;                     break;             }         }         public function Release(event:KeyboardEvent):void         {             switch ( event.keyCode )             {                 case Keyboard.UP :                     _movingUp = false;                     break;                 case Keyboard.DOWN :                     _movingDown = false;                     break;                 case Keyboard.LEFT :                     _movingLeft = false;                     break;                 case Keyboard.RIGHT :                     _movingRight = false;                     break;             }         }     } }

Also u can dl the fla, for CS3. Need help plz.
Attached Files
File Type: zip Test.zip (8.2 KB, 54 views)
Jigrael is offline   Reply With Quote
Old 11-15-2010, 07:43 AM   #2
Jigrael
Registered User
 
Join Date: Nov 2010
Posts: 2
Default

Im not really sure why but I was publishing in Flash 9. I changed it to flash 10 and it worked!! so its Fixed.
Jigrael 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


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