Welcome to Delicate template
Header
Just another WordPress site
Header

flash as2和as3的右键菜单和加载条代码

8月 9th, 2011 | Posted by 无 名 in flash

在用到flash中,经常要写到右键菜单和加载条,下面我将as2和as3的代码整理出来,供大家参考。
1、as2的代码:
as2右键菜单代码:

右键菜单 = new ContextMenu();
eval("右键菜单").hideBuiltInItems();
eval("右键菜单").customItems.push(new ContextMenuItem("小佳", dj_menu0, false));
_root.menu = eval("右键菜单");
function dj_menu0() {
getURL("xiaojia.info", "_blank");
}

as2加载条代码:
第一帧:

byteloaded = getBytesLoaded();
bytetotal = getBytesTotal();
loaded = int(byteloaded / bytetotal * 100);
bartxt.text = loaded + "%";
bar.gotoAndStop(loaded);

第二帧:

if (byteloaded == bytetotal)
{
    gotoAndPlay(3);
}
else
{
    gotoAndPlay(1);
} // end else if

2、as3的代码:
as3右键菜单:

var myContextMenu:ContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var item:ContextMenuItem = new ContextMenuItem("小佳");
myContextMenu.customItems.push(item);
this.contextMenu = myContextMenu;
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectHandler);
function itemSelectHandler(event:ContextMenuEvent):void {
var urlrq:URLRequest = new URLRequest("xiaojia.info");
navigateToURL(urlrq,"_blank");
}

as3加载条:

stop();
import flash.display.LoaderInfo;
import flash.events.ProgressEvent;
myload.addEventListener(Event.ENTER_FRAME,onEnterFramee);
function onEnterFramee (event:Event) {
    if (framesLoaded==totalFrames) {
        //trace(1);
        myload.removeEventListener(Event.ENTER_FRAME,onEnterFramee);
		gotoAndPlay(2);
        //nextFrame();
    }
    else {
        var percent:Number=root.loaderInfo.bytesLoaded/root.loaderInfo.bytesTotal;
        var m:Number=Math.round(percent*100);
        myload.gotoAndStop(m);
        bartxt.text=m+"%";
    }
}//myload为场景中预设的loading动画的MC名字

同时可以看出as2和as3代码有很大的不同。

You can follow any responses to this entry through the RSS 2.0 Both comments and pings are currently closed.