PDA

View Full Version : problem with error 1061


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.

dr_zeus
10-19-2007, 09:17 PM
You specify that thePlayer is type DisplayObject, but the DisplayObject class does not have a movePlayer() function. You should cast thePlayer to the correct type, Player.

var thePlayer:Player = Player(this.parent.parent.getChildByName("player"));
thePlayer.movePlayer();

sermolux
10-19-2007, 10:38 PM
Thank you... works now.

speedclimb
06-26-2008, 10:30 PM
Josh,

Great answer. Error 1061 is thrown every time the DisplayObject is accessed as if it were a movieclip/sprite. I have a few more answers ActionScript Error 1061 (http://curtismorley.com/2008/05/08/flash-flex-3-error-1061-call-to-a-possibly-undefined-method-gotoandstop-through-a-reference-with-static-type-flashdisplaydisplayobject/) on my blog. I hope this helps.

Curtis J. Morley
www.curtismorley.com (http://www.curtismorley.com)