0
votes

I have a swf called console which loads another swf name level. Level has a function called pauseLevel which is called from console. The pauseLevel function is called during loadLevelDone processing. It is also called when message boxes are displayed or when the pause button is clicked. The first time level is loaded the pauseLevel function works properly. The second time it is loaded when pauseLevel is called during loadLevelDone it throws the following error.

TypeError: Error #1034: Type Coercion failed: cannot convert BugEvent@51a4f81 to BugEvent. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.display::Stage/dispatchEvent() at LevelMain/pauseLevel() at Main/pauseLevel()[C:\Users\Herb\Documents\Flash\BugEscape\console\code\Main.as:1811] at Main/loadLevelDone()[C:\Users\Herb\Documents\Flash\BugEscape\console\code\Main.as:1658]

This is the pauseLevel code:

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;
        }
    }

This is my event handler:

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);
    }
}
1

1 Answers

0
votes

Check if you have imported the same BugEvent, check if you have several "BugEvent" in your project.

For example, if you have

com.buglife.BugEvent And com.buglife.event.BugEvent

It will be different class