0
這裏是我的GamePlay.as我有調用類函數我的遊戲類中
package com.work.scripts
{
import flash.display.Stage;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import com.work.scripts.player.Player;
public class GamePlay
{
private var player:Player;
private var stageRef:Stage;
//timers
private var gameDelay:Timer = new Timer(500, 1);
public function GamePlay(stageRef:Stage)
{
this.stageRef = stageRef;
//player variables
player = new Player();
player.x = 400;
player.y = 500;
//
gameDelay.addEventListener(TimerEvent.TIMER_COMPLETE, StartGame, false, 0, true);
gameDelay.start();
}
private function StartGame(e:TimerEvent):void
{
stageRef.addChild(player);
stageRef.addEventListener(Event.ENTER_FRAME, MainGameLoop, false, 0, true);
}
private function MainGameLoop(e:Event):void
{
player.Movement();
}
}
}
和我的課Player.as
package com.work.scripts.player
{
import flash.display.MovieClip;
import flash.events.Event;
import scripts.utils.Bounds;
public class Player extends MovieClip
{
private var bounds:Bounds = new Bounds();
public function Player()
{
}
public function Movement():void
{
startDrag(true, bounds.playArea);
}
}
}
一個問題,我得到這個錯誤
TypeError: Error #1006: Movement is not a function.
at com.socialplay.scripts::GamePlay/MainGameLoop()
這是否意味着我必須爲GamePlay.as中的所有對象製作移動函數,我假設我可以在其他位置調用函數呃只要他們是公開的。
是的,原來Player.as類與Player.as附加到庫中的對象不一樣。我覺得這裏很傻,我想我會接受你的答案可以關閉這個。 – RamenNoodles 2011-03-23 15:36:32