日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

AS3 CookBook学习整理(一)

發(fā)布時(shí)間:2023/12/10 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AS3 CookBook学习整理(一) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1. 我要改變swf的尺寸和顏色

在flex builder 3里,默認(rèn)會(huì)生成一個(gè)全屏、背景色為#869CA7、幀數(shù)為24/秒的swf文件,要修改這些參數(shù),只需要在類文件中定義 [SWF(width="800", height="600", backgroundColor="#ffffff", frameRate="31")]

hxw {flash.display.Sprite;[SWF(width=, height=, backgroundColor=, frameRate=)]ExampleApplicationSprite{ExampleApplication(){}} }

2. 我要重復(fù)執(zhí)行某段代碼

在enterFrame事件中添加監(jiān)聽器和關(guān)聯(lián)處理方法

hxw {flash.display.Sprite;flash.events.Event;Sample1009Sprite{Sample1009(){graphics.lineStyle(3,0xFF0000,1);addEventListener(Event.ENTER_FRAME,onEnterFrame);}onEnterFrame(event:Event):{graphics.lineTo(Math.random()*400,Math.random()*400);}} }

3. 如何響應(yīng)鼠標(biāo)事件

為MouseEvent系列事件添加監(jiān)聽器和關(guān)聯(lián)處理方法

hxw {flash.display.Sprite;flash.events.MouseEvent;[SWF(width=, height=, backgroundColor=, frameRate=)]Sample1010Sprite{_sprite:Sprite;Sample1010(){_sprite = Sprite();_sprite.graphics.beginFill(0x27496E);_sprite.graphics.drawRect(5,5,400,400);_sprite.graphics.endFill();_sprite.addEventListener(MouseEvent.MOUSE_DOWN,OnMouseDown);_sprite.addEventListener(MouseEvent.MOUSE_UP,OnMouseUp);.addChild(_sprite);}OnMouseDown(event:MouseEvent):{_sprite.graphics.lineStyle(1,0xFFFF00,1);_sprite.graphics.moveTo(mouseX,mouseY);_sprite.addEventListener(MouseEvent.MOUSE_MOVE,OnMouseMove);}OnMouseUp(event:MouseEvent):{_sprite.removeEventListener(MouseEvent.MOUSE_MOVE,OnMouseMove);}OnMouseMove(event:MouseEvent):{ _sprite.graphics.lineTo(mouseX,mouseY);}} }

4. 如何響應(yīng)鍵盤事件

為KeyboardEvent事件添加監(jiān)聽器和關(guān)聯(lián)處理方法

{flash.display.Sprite;flash.events.KeyboardEvent;Sample1030Sprite{Sample1030(){stage.addEventListener(KeyboardEvent.KEY_DOWN,OnKeyDown);}OnKeyDown(event:KeyboardEvent):{(event.charCode);}} }

5. 如何實(shí)現(xiàn)定時(shí)器(Timer)

初始化一個(gè)Timer類,使用addEventListener來(lái)設(shè)置一個(gè)函數(shù)處理這個(gè)事件,然后使用timer的start( )方法啟動(dòng)或stop( )停止它。

{flash.display.Sprite;flash.events.TimerEvent;flash.utils.Timer;Sample1101Sprite{_rect:Sprite;_circle:Sprite;Sample1101(){_rect = Sprite();_circle = Sprite();_rect.graphics.beginFill(0xFFFF00);_rect.graphics.drawRect(0,0,100,100);_rect.graphics.endFill();_rect.x = 50;_rect.y = 100;.addChild(_rect);_circle.graphics.beginFill(0x80C56E);_circle.graphics.drawCircle(0,0,50);_circle.graphics.endFill();_circle.x = 100;_circle.y = 200;.addChild(_circle);_timer:Timer = Timer(50);_timer.addEventListener(TimerEvent.TIMER,OnTimerTick);_timer.addEventListener(TimerEvent.TIMER,OnTimerTick2);_timer.start();}OnTimerTick(event:TimerEvent):{_rect.x += 20;}OnTimerTick2(event:TimerEvent):{_circle.y += 30;}} }

6. 獲得客戶端的操作系統(tǒng)版本

ActionScript 3.0中,flash.system.Capabilities.os 屬性返回操作系統(tǒng)名稱和版本字符串。值可能包括Windows XP, Windows 2000, Windows NT, Windows 98/Me, Windows 95, 和Windows CE. 在蘋果機(jī)上,字符串包括版本號(hào),比如Mac OS 9.2.1 或Mac OS X 10.4.4

{flash.display.Sprite;flash.system.Capabilities;Sample1101Sprite{Sample1101(){os:String = flash.system.Capabilities.os.substr(0,3);if (os == ) {}else if (os == ) {}else {}}} }

7. 獲得客戶端的播放器類型

使用flash.system.Capabilities.playerType屬性。它可能是PlugIn, ActiveX,StandAlone和External。

播放器的類型有:

瀏覽器插件形式存在于Mozilla 或Firefox

ActiveX 控件形式存在于Internet Explorer

獨(dú)立播放器

外部播放器,它與Flash IDE進(jìn)行交互

{flash.display.Sprite;flash.system.Capabilities;Sample1101Sprite{Sample1101(){(flash.system.Capabilities.playerType == ){}else (flash.system.Capabilities.playerType == ){}else{}}} }

8. 獲得客戶端的語(yǔ)言與輸入法

使用flash.system.Capabilities.language 屬性和flash.system.IME 類

{flash.display.Sprite;flash.system.IME;Sample1101Sprite{Sample1101(){lang:String = flash.system.Capabilities.language.substr(0, 2);>?supportedLanguages:Array = [, , ];useLang:String = ;for (i:int = 0; i < supportedLanguages.length; i++){if (supportedLanguages[i] == lang){useLang = lang;break;}}movieURL:String = + useLang + ;}} }

9. 獲得客戶端的分辨率

screenResolutionX 和screenResolutionY 屬性返回桌面的顯示分辨率:

trace(flash.system.Capabilities.screenResolutionX); // 1024

trace(flash.system.Capabilities.screenResolutionY); // 768

{flash.display.Sprite;flash.external.ExternalInterface;flash.system.Capabilities;Sample1101Sprite{Sample1101(){screenX:int = flash.system.Capabilities.screenResolutionX;screenY:int = flash.system.Capabilities.screenResolutionY;winW:int = 200;winH:int = 200;winX:int = (screenX / 2) - (winW / 2);winY:int = (screenY / 2) - (winH / 2);jsCode:String = ++ winW ++ winH + ++ winX + + winY + ;ExternalInterface.call(jsCode);}} }

10. 縮放影片

設(shè)置stage.scaleMode,scaleMode屬性值并不影響右鍵菜單里功能,不過(guò)你可以禁用菜單里的縮放功能。

stage.scaleMode的值來(lái)自flash.display.StageScaleMode類的枚舉,有EXACT_FIT, NO_BORDER,NO_SCALE, 和SHOW_ALL

假設(shè)原影片如下:

1. SHOW_ALL

這種模式會(huì)成比例縮小與放大。如果播放器與影片的比例不一致,則會(huì)出現(xiàn)空白邊框。以SHOW_ALL模式縮小后的效果如下:

2. EXACT_FIT

這種模式會(huì)不成比例縮小與放大。以EXACT_FIT模式縮小后的效果如下:

3. NO_BORDER

這種模式會(huì)成比例縮小與放大。如果播放器和影片比例不一致,則會(huì)裁剪影片。以NO_BORDER模式縮小后的效果如下:

4. NO_SCALE

這種模式不進(jìn)行縮放,保持原有比例。使用該模式不要忘了設(shè)置對(duì)齊方式。

轉(zhuǎn)載于:https://www.cnblogs.com/CoderWayne/archive/2010/07/15/1778031.html

總結(jié)

以上是生活随笔為你收集整理的AS3 CookBook学习整理(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。