作为2到as3的转换

时间:2011-04-06 13:47:00

标签: flash actionscript-3

如何将此as2代码翻译为as3?

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

2 个答案:

答案 0 :(得分: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");
}

答案 1 :(得分: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