A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Can someone please help me with my class

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1

    Can someone please help me with my class

    I've been trying to get my class working and every time I fix an error another one just pops up in it's place. I've attached a zip file containing my current files.

    Code:

    package{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class EnemyPic extends MovieClip{
    public function EnemyPic()
    }
    addEventListener(Event.ADDED_TO_STAGE, init);
    {
    function init(e:Event):void
    {
    // constructor code
    trace ("EnemyPic Constructer")
    addEventListener(Event.ENTER_FRAME, eFrame);
    }

    function eFrame(e:Event):void{
    if (ep.x > this.stage.stageWidth + 80)
    {
    ep.x = -80;
    }
    }
    }
    }
    Attached Files Attached Files

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
     package {
             import flash.display.*;
    
             public class Game extends MovieClip {
    // note - changed background to Background
                     private var bg:Background;
                     private var pp:PlayerPic;
                     private var ep:EnemyPic;
    
                     public function Game() {
                             trace("Game Constructer");
                             var bg = new Background();
                             addChild(bg);
                             pp = new PlayerPic();
                             pp.x = 125;
                             pp.y = 550;
                             pp.width = 50;
                             pp.height = 40;
                             addChild(pp);
                             ep = new EnemyPic();
                             ep.x = 55;
                             ep.y = 50;
                             ep.height = 40;
                             ep.width = 50;
                             addChild(ep);
                     }
             }
     }
    Code:
     package {
             import flash.display.*;
             import flash.events.*;
             import flash.ui.*;
    
             public class PlayerPic extends MovieClip {
    
                     public function PlayerPic() {
                             addEventListener(Event.ADDED_TO_STAGE, init);
                             trace("PlayerPic Constructer");
                     }
                     private function init(e:Event):void {
                             removeEventListener(Event.ADDED_TO_STAGE, init);
                             stage.addEventListener(KeyboardEvent.KEY_DOWN, arrowMove);
                     }
                     private function arrowMove(e:KeyboardEvent):void {
                             if (e.keyCode == Keyboard.LEFT) {
                                     x -=  5;
                                     if (x < 0) {
                                             x = 0;
                                     }
                             }
                             if (e.keyCode == Keyboard.RIGHT) {
                                     x +=  5;
                                     if (x > 250) {
                                             x = 250;
                                     }
                             }
                             if (e.keyCode == Keyboard.UP) {
                                     y -=  5;
                                     if (y < 0) {
                                             y = 0;
                                     }
                             }
                             if (e.keyCode == Keyboard.DOWN) {
                                     y +=  5;
                                     if (y > 550) {
                                             y = 550;
                                     }
                             }
                     }
             }
     }
    Code:
     package {
             import flash.display.*;
             import flash.events.*;
    
             public class EnemyPic extends MovieClip {
    
                     public function EnemyPic() {
                             trace("EnemyPic Constructer");
                             addEventListener(Event.ADDED_TO_STAGE, init);
                     }
                     private function init(e:Event):void {
                             removeEventListener(Event.ADDED_TO_STAGE, init);
                             addEventListener(Event.ENTER_FRAME, eFrame, false,0, true);
                     }
                     public function eFrame(e:Event):void {
                             if (x > this.stage.stageWidth + 80) {
                                     x = -80;
                             }
                     }
             }
     }
    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center