Adobe Air & Adobe Flex & ActionScript & RIA & User Experience

關注創業的朋友們可以看看最近網易的創業者課堂,并且十分推薦這2位導師 查立 & 史蒂芬·哈蒙,總能在他們的文章中看清楚創業者的方向。
如何在商場中尋找創業機遇,如何找到合作伙伴,如何制作創業書,如何得到VC的投資,導師們都給出了很好的建議。
Adobe Flex 工程的 Application 為2幀的動畫,第1幀為 Pre-load,第2幀為 Application,如果想替換 Adobe Flex 原有的 Pre-loader,那么制作將非常的方便。制作一個新的 preload Component,在 Application 的 preloader 屬性中進行相關的引用就可以完成。
這次討論的不是在 AS3 工程中直接加載 SWF,而是通過 getDefinitionByName(name:String) 的方式對 Application 進行動態加載。
例子是 Unique Instance,詳細請見 Application.as 關于 Instance 的寫法。
代碼:
PreloaderApp.as
package { import flash.display.DisplayObject; import flash.display.MovieClip; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.ProgressEvent; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.utils.getDefinitionByName; public class PreloaderApp extends MovieClip { /** * PreloaderApp Constructor. */ public function PreloaderApp() { this.addEventListener(Event.ADDED_TO_STAGE, handleToStage); } /** * Handle ADDED_TO_STAGE event. * @param event */ private function handleToStage(event:Event):void { this.removeEventListener(Event.ADDED_TO_STAGE, handleToStage); //stage setting stage.showDefaultContextMenu = false; stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; createChildren(); addEventListener(Event.ENTER_FRAME, loadApplication); this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress); this.loaderInfo.addEventListener(Event.COMPLETE, handleComplete); } private var _preLoadingText:TextField; /** * createChildren */ private function createChildren():void { _preLoadingText = new TextField(); _preLoadingText.text = "Loading..."; _preLoadingText.textColor = 0x000000; _preLoadingText.x = (stage.stageWidth / 2) - (_preLoadingText.width / 2); _preLoadingText.y = (stage.stageHeight / 2) - (_preLoadingText.height / 2); _preLoadingText.autoSize = TextFieldAutoSize.CENTER; addChild(_preLoadingText); } /** * Handle progress. * @param event */ private function handleProgress(event:ProgressEvent):void { var percent:int = Math.floor(event.bytesLoaded / event.bytesTotal * 100); _preLoadingText.text = "Loading..." + percent + "%"; } /** * Handle load complete. * @param event */ private function handleComplete(event:Event):void { this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, handleProgress); this.loaderInfo.removeEventListener(Event.COMPLETE, handleComplete); } /** * Load main application. * @param e */ private function loadApplication(event:Event):void { if (currentFrame == totalFrames) { removeEventListener(Event.ENTER_FRAME, loadApplication); stop(); var cls:Class = getDefinitionByName("Application") as Class; addChild(new cls() as DisplayObject); removeChild(_preLoadingText); _preLoadingText = null; } } } }
Application.as
package { import flash.display.Sprite; import flash.events.Event; public class Application extends Sprite { private static var _instance:Application; /** * Unique instance. * @return */ public static function getInstance():Application { return _instance; } /** * Application Constructor. */ public function Application() { super(); addEventListener(Event.ADDED_TO_STAGE, initOnStage); } /** * Handle ADDED_TO_STAGE event. * @param event */ protected function initOnStage(event:Event):void { //remove ADDED_TO_STAGE listener. this.removeEventListener(Event.ADDED_TO_STAGE, initOnStage); //Set unique instance. if (!_instance) _instance = this; //... } } }
前段時間重新為臺灣的ING投資理財網定制了2個基金圖表,工程已經接近完成,因此也拿出來分享一下。
擁有自定義基于Adobe Flex UIComponent的4個組件:
NetValueChart & PerformanceChart支持同時顯示多條曲線,比起Adobe Flex自帶的Chart Component運算速度更快,效能更佳,功能也更多,
。
HDividedCanvas & HDividedSlider是一個區間選擇组件。
這次 YouTube Chromeless Player API 對 ActionScript 3 的支持堪稱完美了!
首先,回顧之前常用的 Youtube Player API,來個部分總結:
1 2 3 4 5 6 7 | //Loading youtube 的 apiplayer,并且設置可以與 Javascript 互動。 private static const CHROMELESS_PLAYER_URL:String="http://www.youtube.com/apiplayer?enablejsapi=1" ... _loader = new Loader(); //_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler); _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); _loader.load(new URLRequest(CHROMELESS_PLAYER_URL)); |
Event.COMPLETE 在這里并不起作用,因此需要通過 ExternalInterface class & JavaScript來判斷相應的 SWF-DIV 來告知CHROMELESS_PLAYER_URL 是否Loading成功,而在Flash里面的每次操作,也是由 ExternalInterface class & JavaScript 來互相控制。
這樣一來,缺點顯而易見:
更多參考:
demo:
http://youtubechromelesswrapper-as3.googlecode.com/svn/trunk/as3wrapper/deploy/index.html
A full article and code overview is available here:
http://code.google.com/apis/youtube/articles/youtube_as3_chromeless.html
Sample Source Code:
ActionScript_3_YouTube_Wrapper_v1.0.zip
更多參考:
http://code.google.com/intl/en/apis/youtube/articles/tubeloc.html
最近再次查看 Youtube Player API
Wednesday, October 14, 2009
the official YouTube Chromeless Player API has been updated to natively support ActionScript 3!
…
讓我眼前一亮。
這次 Youtube 的更新支持 YouTube Chromeless Player 不再需要通過 JS 或者 localConnection 的方式進行通信連接,直接采用 ActionScript3 的內部方式。
1 2 3 | //注意這次的地址,后面加了參數version = 3。 //如果沒有這個version=3的參數,那么 YouTube Chromeless Player API 將無法使用的 private static const CHROMELESS_PLAYER_URL:String="http://www.youtube.com/apiplayer?version=3"; |
而檢測 Player 是否成功載入的方式采用的是它本身內部的監聽,目前提供了:
“onReady” – 載入成功
“onError” – 載入異常
“onStateChange” – 播放器狀態改變
“onPlaybackQualityChange” – 播放器影片載入質量改變
1 2 3 4 | _youtubeLoader.content.addEventListener("onReady", onPlayerReady); _youtubeLoader.content.addEventListener("onError", onPlayerError); _youtubeLoader.content.addEventListener("onStateChange", onPlayerStateChange); _youtubeLoader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange); |
而使用方法,也是在 _youtubeLoader 在完全 Loading 完成 youtubePlayer 以后,直接進行調用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | /** * loadByURL * @param url YouTube player URL in the format http://www.youtube.com/v/VIDEO_ID. * @param seconds */ public function loadByURL(url:String, seconds:Number = 0):void { if (youtubePlayer) { if (_autoPlay) { //Loads and plays the specified video. youtubePlayer.loadVideoByUrl(url, seconds); } else { //The player does not request the FLV until playVideo() or seekTo() is called. youtubePlayer.cueVideoByUrl(url, seconds); } } } |
而且經過測試,可以支持多個播放器同時播放。
本人也寫了個 AS3 的類供大家玩耍(因為要連接 Youtube.com,所以國內的同學請繞墻),可以參考源代碼。
http://code.richmediaplus.com/ChromelessYoutubePlayerAS3/ChromelessYoutubePlayerAS3App.html
SourceView:http://code.richmediaplus.com/ChromelessYoutubePlayerAS3/srcview/
更多參考(國內的同學請注意跳轉地址):
http://code.google.com/intl/en/apis/youtube/flash_api_reference.html
至于 Full-Chrome player 的這一塊,經本人測試,如果loading的地址采用的是”http://www.youtube.com/v/VIDEO_ID?version=3″,那么loading襲來的swf照樣可以支持目前提供的API,但是因為Flash security的限制,DEBUG版本播放器下會報錯誤,但是普通版本可以測試通過。畢竟 Full-Chrome player 的 API 還沒有正式提供,所以也不建議大家使用。
真的播放器在 http://s.ytimg.com/yt/swf/watch_as3.swf 這里啊,但是人家限制域啦!