2011-04-06 68 views
-1

如何將as2代碼轉換爲as3?as 2 as3 conversion

topHome_mc.onRollOver = function () { 
topHome_mc.gotoAndPlay("over"); 
} 

topHome_mc.onRollOut = function () { 
    topHome_mc.gotoAndPlay("out"); 
} 

topHome_mc.onRelease = function() { 
    mcLoader.loadClip("home.swf",myLoader); 
    stick("gh_mc"); 
} 

回答

0
//add the listeners to the object 
topHome.addEventListener(MouseEvent.MOUSE_OVER,onMouseOverHandler); 
topHome.addEventListener(MouseEvent.MOUSE_OUT,onMouseOutHandler); 
topHome.addEventListener(MouseEvent.CLICK,onMouseClickHandler); 

//handle rollover 
function onMouseOverHandler(event:MouseEvent):void 
{ 
    event.target.gotoAndPlay("over"); 
} 
//handle roll out 
function onMouseOutHandler(event:MouseEvent):void 
{ 
    event.target.gotoAndPlay("out"); 
} 
//handle click 
function onMouseClickHandler(event:MouseEvent):void 
{ 
    var loader:Loader = new Loader(); 
    loader.load(new URLRequest('home.swf')); 
    //assume myLoader is already created 
    myLoader.addChild(loader); 
    stick("gh_mc"); 
} 
0
// add our mouse listeners 
topHome_mc.addEventListener(MouseEvent.MOUSE_OVER, this._onOver); 
topHome_mc.addEventListener(MouseEvent.MOUSE_OUT, this._onOut); 
topHome_mc.addEventListener(MouseEvent.CLICK, this._onClick); 

// called when we mouse over it 
private function _onOver(e:MouseEvent):void 
{ 
    topHome_mc.gotoAndPlay("over"); 
} 

// called when we mouse out of it 
private function _onOut(e:MouseEvent):void 
{ 
    topHome_mc.gotoAndPlay("out"); 
} 

// called when we click on it 
private function _onClick(e:MouseEvent):void 
{ 
    // create a loader to load the swf 
    var l:Loader = new Loader(); 
    l.load(new URLRequest("home.swf")); 
    myLoader.addChild(l); 

    // do whatever this does 
    stick("gh_mc"); 
} 

爲Loader對象,你可能應該添加事件偵聽器的不同狀態的事件:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#includeExamplesSummary