Hey I’m new to the forums, I’m having a lot of trouble understanding a certain thing.
I’m creating a child of a symbol in my ‘main’ class
var player:Symbol3 = new Symbol3();
addChild(player);
player.x = 400;
player.y = 200;
I have no idea how to access ‘player’ from a seperate class? I would like to change x and y coords from a seperate class. However when I use code like ‘player.x = player.x + 2’ i get the error message Line 17 1120: Access of undefined property player.
I guess in the most simple words, I do not know how to access symbols or their children from a class that is not the document class.
These are my full lines of code.
package
{
import flash.events.TouchEvent;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.events.Event;
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
public class Main extends MovieClip
{
/** THESE ARE SIMPLY THE VARIABLES THAT ARE CONTROLLED BY THE MULTITOUCH INPUTS. */
var upispressed:Boolean = false;
var downispressed:Boolean = false;
var rightispressed:Boolean = false;
var leftispressed:Boolean = false;
private var upVar;
public function Main()
{
/** THESE FOLLOWING LINES OF CODE ARE SETTING UP THE MULTITOUCH INPUT. BASICALLY THE BEGINNING
OF A TOUCH WILL TURN "upispressed TRUE" AND WHEN RELEASED IT WILL BE FALSE*/
/*instance*/
moveup.addEventListener(TouchEvent.TOUCH_OVER, upbutton);/** func name */
moveup.addEventListener(TouchEvent.TOUCH_OUT, notupbutton);
movedown.addEventListener(TouchEvent.TOUCH_OVER, downbutton);
movedown.addEventListener(TouchEvent.TOUCH_OUT, notdownbutton);
moveright.addEventListener(TouchEvent.TOUCH_OVER, rightbutton);/** func name */
moveright.addEventListener(TouchEvent.TOUCH_OUT, notrightbutton);
moveleft.addEventListener(TouchEvent.TOUCH_OVER, leftbutton);
moveleft.addEventListener(TouchEvent.TOUCH_OUT, notleftbutton);
// test stuff;
moveup.addEventListener(MouseEvent.MOUSE_OVER, upbutton);/** func name */
moveup.addEventListener(MouseEvent.MOUSE_OUT, notupbutton);
movedown.addEventListener(MouseEvent.MOUSE_OVER, downbutton);
movedown.addEventListener(MouseEvent.MOUSE_OUT, notdownbutton);
moveright.addEventListener(MouseEvent.MOUSE_OVER, rightbutton);/** func name */
moveright.addEventListener(MouseEvent.MOUSE_OUT, notrightbutton);
moveleft.addEventListener(MouseEvent.MOUSE_OVER, leftbutton);
moveleft.addEventListener(MouseEvent.MOUSE_OUT, notleftbutton);
var player:Symbol3 = new Symbol3();
addChild(player);
player.x = 400;
player.y = 200;
//*these need to be changed to touch events when deployed for ipod
function upbutton( event:MouseEvent):void
{
upispressed = true;
player.x += 2;
upVar = new Movement();
upVar.Up();
}
function notupbutton(event:MouseEvent):void
{
upispressed = false;
}
function downbutton( event:MouseEvent):void
{
downispressed = true;
}
function notdownbutton(event:MouseEvent):void
{
downispressed = false;
}
function rightbutton( event:MouseEvent):void
{
rightispressed = true;
}
function notrightbutton(event:MouseEvent):void
{
rightispressed = false;
}
function leftbutton( event:MouseEvent):void
{
leftispressed = true;
}
function notleftbutton(event:TouchEvent):void
{
leftispressed = false;
}
/** THIS IS THE END OF THE TOUCH INPUT COMMANDS. AT THIS POINT THE VARIABLES
leftispressed, rightispressed, upispressed, downispressed WILL BE USED AS THE
PLAYER CONTROLLERS. */
}
}
}
package
{
import flash.display.MovieClip;
import Main;
import flash.events.Event;
public class Movement extends MovieClip
{
public function Up() {
player.x = player.x +3
}
}
}
Basically I just am curious as to why I can’t simply access these items from another class?