as 2 to as3 conversion
How to translate this as2 code to as3?
topHome_mc.onRollOver = function () {
topHome_mc.gotoAndPlay("ov开发者_运维问答er");
}
topHome_mc.onRollOut = function () {
topHome_mc.gotoAndPlay("out");
}
topHome_mc.onRelease = function() {
mcLoader.loadClip("home.swf",myLoader);
stick("gh_mc");
}
//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");
}
// 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" );
}
For the Loader object, you should probably be adding event listeners for the different status events: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#includeExamplesSummary
精彩评论