我有一个名为console的swf,它会加载另一个swf名称级别。 Level有一个名为pauseLevel
的函数,它从控制台调用。在pauseLevel
处理期间调用loadLevelDone
函数。当显示消息框或单击暂停按钮时也会调用它。加载第一个时间级别pauseLevel
功能正常工作。第二次在pauseLevel
期间调用loadLevelDone
时加载它会引发以下错误。
TypeError:错误#1034:类型强制失败:无法转换 BugEvent @ 51a4f81到BugEvent。在 flash.events :::EventDispatcher / dispatchEventFunction()at flash.events :::EventDispatcher / dispatchEvent()at 在LevelMain / pauseLevel()处的flash.display :: Stage / dispatchEvent() 主/ pauseLevel()[C:\用户\香草\文件\闪存\ BugEscape \控制台\代码\ Main.as:1811] 在 主/ loadLevelDone()[C:\用户\香草\文件\闪存\ BugEscape \控制台\代码\ Main.as:1658]
这是pauseLevel代码:
public function pauseLevel():void
{
if (levelPaused){
stage.dispatchEvent(new BugEvent(BugEvent.PAUSE_GAME, 0, 0, 3,"unpause"));
levelPaused = false;
}else{
stage.dispatchEvent(new BugEvent(BugEvent.PAUSE_GAME, 0, 0, 3,"pause"));
levelPaused = true;
}
}
这是我的事件处理程序:
public class BugEvent extends Event{
public static const COIN_HIT: String = "cHit";
public static const BOX_HIT: String = "bHit";
public static const ADD_POINTS: String = "addPoints";
public static const EXIT_HIT: String = "eHit";
public static const JUMP: String = "jump";
public static const KILL_BUG: String = "kBug";
public static const KILL_PLAYER: String = "kPlayer";
public static const REMOVE_BUG: String = "rBug";
public static const REMOVE_BOX: String = "rBox";
public static const PLAY_SX: String = "playSX";
public static const DB_DONE: String = "dbDone";
public static const PAUSE_GAME: String = "pauseGame";
public var tileX:int;
public var tileY:int;
public var swapTo:int;
public var killType:String;
public var eventValue:int;
public function BugEvent(type:String,tx:int,ty:int,st:int,kt:String="",ev:int = 0,bubbles:Boolean=false, cancelable:Boolean=false)
{
tileX = tx;
tileY = ty;
swapTo = st;
killType = kt;
eventValue = ev;
super(type, bubbles, cancelable);
}
override public function clone():Event
{
return new BugEvent (type,tileX,tileY,swapTo,killType,eventValue, bubbles, cancelable);
}
}
答案 0 :(得分:0)
检查您是否导入了相同的BugEvent,检查项目中是否有多个“BugEvent”。
例如,如果你有
com.buglife.BugEvent 和 com.buglife.event.BugEvent
这将是不同的类