sermolux
10-19-2007, 07:47 PM
I've got a MovieClip object job that is a child of another MovieClip counter which is a child of the stage. I also have another MovieClip object player (with an instance name of player) that is also a child of the stage. I've defined a custom class for the player and job objects. A portion of the player:
package Cpc
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Player extends MovieClip
{
public function Player()
{
trace( "Player Created" );
}
public function movePlayer():void
{
trace( "Moving Player" );
}
}
}
I am trying to access the method movePlayer from the job instance:
package Cpc
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Job extends MovieClip
{
public function Job()
{
addEventListener( MouseEvent.CLICK, mouseClick );
}
function mouseClick( e:MouseEvent ):void
{
trace( "Clicked: " + this.name );
var thePlayer:DisplayObject = this.parent.parent.getChildByName( "player" );
thePlayer.movePlayer();
}
}
}
When I test my code, i get:
1061: Call to a possibly undefined method movePlayer through a reference with static type flash.display: DisplayObject.
Please help.
Thanks.
package Cpc
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Player extends MovieClip
{
public function Player()
{
trace( "Player Created" );
}
public function movePlayer():void
{
trace( "Moving Player" );
}
}
}
I am trying to access the method movePlayer from the job instance:
package Cpc
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Job extends MovieClip
{
public function Job()
{
addEventListener( MouseEvent.CLICK, mouseClick );
}
function mouseClick( e:MouseEvent ):void
{
trace( "Clicked: " + this.name );
var thePlayer:DisplayObject = this.parent.parent.getChildByName( "player" );
thePlayer.movePlayer();
}
}
}
When I test my code, i get:
1061: Call to a possibly undefined method movePlayer through a reference with static type flash.display: DisplayObject.
Please help.
Thanks.