Skip navigation
Currently Being Moderated

Flash Pro with Flex 4 class linkage problem

Jul 29, 2012 3:31 PM

Flash Professional Project, using FLEX 4 to edit code:

I am working in Flash Pro to create assets, the code to which I would like to edit in Flash builder. It seems that when I compile, the linkage names for objects in Flash Pro conflict with the actual class files.

 

Ex: In my document class, I trace to get a parameter 'pSpeed' in my player class which is a num value set to 5, but the trace comes back undefined. Any idea what I'm doing wrong?

 

Screen Shot 2012-07-28 at 12.58.08 PM.png

 

Screen Shot 2012-07-29 at 3.21.47 PM.png

 

TestGameA.as (document class)

package

{

          import gamepack.*;

          import flash.display.Sprite;

 

          public class TestGameA extends Sprite

          {

                    public var game:Game;

                    public var p1:Player;

 

                    public function TestGameA()

                    {

                              trace("I am TestGameA constructor");

                              addChild(game = new Game());

                              game.x = 300;

                              game.y = 300;

                              addChild(p1 = new Player());

                              trace(p1.pSpeed); //comes back 'undefined'

                    }

          }

}

 

Game.as

package gamepack

{

          import flash.display.MovieClip;

 

          public class Game extends MovieClip

          {

                    public function Game()

                    {

                             trace ("I am Game Constructor");

                    }

          }

}

 

Player.as

package gamepack

{

          import flash.events.*;

          import flash.display.*;

          import flash.ui.*;

 

          public class Player extends MovieClip

          {

                    public var pSpeed:Number = 5;

 

  //CONSTRUCTOR

                    public function Player()

                    {

                              trace ("I am Player Constructor");

                              addEventListener(Event.ADDED_TO_STAGE, pLoaded);

                    }

 

  //ADDED TO STAGE

                    public function pLoaded(e:Event):void

                    {

                              trace("player wants to move");

                              gotoAndStop(1);

                              addEventListener(KeyboardEvent.KEY_DOWN, pInput);

                    }

 

  //KEYBOARD MOVEMENT

                    function pInput(key:KeyboardEvent):void

                    {

                              switch (key.keyCode)

                              {

                                        case 37 ://Left

                                                  scaleX = -1; //flip horiz.

                                                  x -=  pSpeed;

                                                  break;

 

                                        case 39 ://Right

                                                  scaleX = 1; //flip horiz.

                                                  x +=  pSpeed;

                                                  break;

 

                                        case 38 ://Up

                                                  y -=  pSpeed;

                                                  break;

 

                                        case 40 ://Down

                                                  y +=  pSpeed;

                                                  break;

                              } 

          }

}

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points