這篇文章描述了使用 compress 並不會減少實際記憶體使用量
以及解決方法
http://etrex.blogspot.com/2011/05/bytearraycompress.html
2011年5月18日 星期三
2011年5月15日 星期日
Getting the total percent loaded from Bulkloader with AS3
The bad News:
Without knowing the total bytes we can’t calculate a percentage. Each file added to BulkLoader’s queue occupies 1 connection. If there are more files than there are connections, BulkLoader can’t accurately retrieve the sizes of those files waiting for a connection to free up.
“This means that the percentLoaded will be 0 almost until all items are loaded, and then it will jump abruptly. Worse, each time a new connection is open, the bytesTotal would jump around (it would add the bytesTotal for the new item). To mitigate this issue, bytesTotal will remain 0 until all file sizes are known.”
Getting the Total Percent Loaded from BulkLoader with Flash ActionScript 3
Without knowing the total bytes we can’t calculate a percentage. Each file added to BulkLoader’s queue occupies 1 connection. If there are more files than there are connections, BulkLoader can’t accurately retrieve the sizes of those files waiting for a connection to free up.
“This means that the percentLoaded will be 0 almost until all items are loaded, and then it will jump abruptly. Worse, each time a new connection is open, the bytesTotal would jump around (it would add the bytesTotal for the new item). To mitigate this issue, bytesTotal will remain 0 until all file sizes are known.”
Getting the Total Percent Loaded from BulkLoader with Flash ActionScript 3
2011年5月8日 星期日
2011年4月13日 星期三
[BulkLoader] Failed to get content with url as type: [class Bitmap]
今天試玩Google image search API, 用bulkloader來載圖,
在flash builder上run的好好的,但放在網路就無法執行。
後來trace bulkloader的ImageItem.as source code
才發現bulkloader在發生cross domain security error時,並不會把err丟出來,反而是把載好圖的loader丟給上層。
回去翻文件,才發現其實文件有寫... XD
所以原本寫的
addChild( imageLoader.getBitmap( key ) );
改寫成
addChild( imageLoader.get( key ).content );
就不會有cross domain security 討人厭的問題了.
Ref:
http://groups.google.com/group/bulkloader-users/browse_thread/thread/31189ad472fb1d90
在flash builder上run的好好的,但放在網路就無法執行。
後來trace bulkloader的ImageItem.as source code
才發現bulkloader在發生cross domain security error時,並不會把err丟出來,反而是把載好圖的loader丟給上層。
回去翻文件,才發現其實文件有寫... XD
SecurityError
BulkLoader can handle SecurityErrorEvents. By listening to BulkLoader.SECURITY_ERROR("securityError"), client code can gracefully handle security error events. Listeners can be added to each LoadingItem subtype or to the entire BulkLoader object. Please note that if you add an event listener for a LoadingItem but not for BulkLoader, in case the event fires, it will bubble up and result in a unhandled security error. In order to make sure the error never goes unhandled, add a securityError handler to the BulkLoader instance.
This mechanism will catch events thrown on
.load operations. Event thrown when trying to access content (such as getBitmapData) is still left to client code to handle.When using type=image or type=movieclip (which are loaded using a Loader instance), if, when the asset is loaded, accessing it's loader.content throws an error, then BulkLoader will gracefully recover and use a simple Loader instance. This way, you can still add a Loader object to the stage, but won't be able to run code inside of it (for MovieClip instances) or load it as data (transforming to BitmapData instances).
In this case, you can get the Loader instance either using getContent or getDisplayObjecLoader .
所以原本寫的
addChild( imageLoader.getBitmap( key ) );
改寫成
addChild( imageLoader.get( key ).content );
就不會有cross domain security 討人厭的問題了.
Ref:
http://groups.google.com/group/bulkloader-users/browse_thread/thread/31189ad472fb1d90
2011年1月19日 星期三
Uniquely random number array generation
http://ticore.blogspot.com/2011/01/as3-unique-random-number.html
三招都很cool!
尤其第三招用了Array.RETURNINDEXEDARRAY會回傳不重覆index array的特性.
超酷!!
Array.RETURNINDEXEDARRAY的用法可參考下面這篇~
http://blogs.adobe.com/actionscriptdocs/tag/returnindexedarray
Ticore大大還用Array.RETURNINDEXEDARRAY
實做簡潔的連續整數(0-n)array
http://ticore.blogspot.com/2011/01/as3-fast-way-generate-integer-sequence.html
三招都很cool!
尤其第三招用了Array.RETURNINDEXEDARRAY會回傳不重覆index array的特性.
超酷!!
Array.RETURNINDEXEDARRAY的用法可參考下面這篇~
http://blogs.adobe.com/actionscriptdocs/tag/returnindexedarray
Ticore大大還用Array.RETURNINDEXEDARRAY
實做簡潔的連續整數(0-n)array
http://ticore.blogspot.com/2011/01/as3-fast-way-generate-integer-sequence.html
Trick on iterating array concatenation
nice trick!!
http://blog.eddie.com.tw/2011/01/18/faster-array-concatenation-in-as3/
array1.push.apply( array1, array2);
http://blog.eddie.com.tw/2011/01/18/faster-array-concatenation-in-as3/
array1.push.apply( array1, array2);
2010年12月2日 星期四
2010年11月15日 星期一
用Movie Clip 實作Button時, mouse event造成不斷閃爍的問題?
往往為了要讓button的mouse event 有更多層次的特效時,
artist 會選擇用movieclip的製作方式來取代simple button.
MovieClip往往有多層元件.
當滑鼠移至母元件與子元件差集的部分,
常常會因為母元件的mouse over event與子元件的mouse out event 發生循環loop,
使得movie clip 產生閃爍, 解決的方法就是僅對母元件註冊mouse event,
並將母元件的mouseChildren 設為false.
2010年11月11日 星期四
How to Compare Two Array
以下轉自ptt flash版
作者 cjcat2266 (CJ Cat) 看板 Flash
標題 Re: [問題] 我想比較兩個陣列的不同?
時間 Sat Oct 9 21:02:33 2010
───────────────────────────────────────
※ 引述《kaiyine (yumi)》之銘言:
: 陣列a是5,2,6,8,4
: 陣列b是0,1,2,3,4,5,6,7,8,9,10
: 我要如何列出陣列a缺少0,1,2,3,7,9,10呢?
這就是"集合"的問題了
同上一篇回文所說的,可以用associative array
(如果是AS3就可以用Dictionary class,相當於C++的map class)
其實可以更簡短的寫
(以下code未經過測試,可能有錯字)
var a:Array = [5, 2, 6, 8, 4];
var b:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
//集合物件
var obj:Object = new Object();
作者 cjcat2266 (CJ Cat) 看板 Flash
標題 Re: [問題] 我想比較兩個陣列的不同?
時間 Sat Oct 9 21:02:33 2010
───────────────────────────────────────
※ 引述《kaiyine (yumi)》之銘言:
: 陣列a是5,2,6,8,4
: 陣列b是0,1,2,3,4,5,6,7,8,9,10
: 我要如何列出陣列a缺少0,1,2,3,7,9,10呢?
這就是"集合"的問題了
同上一篇回文所說的,可以用associative array
(如果是AS3就可以用Dictionary class,相當於C++的map class)
其實可以更簡短的寫
(以下code未經過測試,可能有錯字)
var a:Array = [5, 2, 6, 8, 4];
var b:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
//集合物件
var obj:Object = new Object();
var i:Number, len:Number;
//讓a的元素作為key,跟true值產生關連
for (i = 0, len = a.length; i < len; ++i) {
obj[a[i]] = true;
}
//尋找"a沒有,b有的元素"
for (i = 0, len = b.length; i < len; ++i) {
//若obj[b[i]]沒有關聯值,那就是undefined,!undefined == true
if (!obj[b[i]]) {
trace("a沒有含" + b[i]);
}
}
==========================================================
作者 etrexetrex (moonet)
也可以存 inverse A,不過其實是一樣的
多花了點記憶體,得到了一些加速
假設:
A陣列中沒有重複出現相同的值
程式:
var i:Number;
var a:Array = [5, 2, 6, 8, 4];
var b:Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var aLength : Number = a.length;
var bLength : Number = b.length;
//建立A的反向表 此處inverseA的型態是陣列
var inverseA:Array = [];
for (i = 0 ; i < aLength; i++ )
inverseA[a[i]] = i;
var inverseALength : Number = inverseA.length;
//多花的記憶體在 inverseA
trace("aLength = " + aLength); //aLength = 5
trace("bLength = " + bLength); //bLength = 11
trace("inverseALength = " + inverseALength); //inverseALength = 9
//尋找"a沒有,b有的元素"
for (i = 0; i < bLength; i++ )
{
//加速在這裡
if(b[i] >= inverseALength)
trace("a沒有含" + b[i]);
//基本上 Array 的存取也會比 Object 快些
else if(inverseA[b[i]] == undefined)
trace("a沒有含" + b[i]);
}
為了確認Array 的空值是 undefined
只好打開 flash cs4
所以上面的程式已經測過了
========================================================
作者 cjcat2266 (CJ Cat)
※ 引述《etrexetrex (moonet)》之銘言:
: //加速在這裡
: if(b[i] >= inverseALength)
補充說明一下
其實這裡不一定會完全加速喔
: //基本上 Array 的存取也會比 Object 快些
要看你的array是不是sparse array
意思就是你是否每一個element都有明確給值
一個Array物件內部底層其實分成一個陣列和一個binary search tree (dictionary)
從第0個開始的元素到最後一個連續的元素,是存在陣列
剩下的元素則是存在binary search tree裡面
這樣才不會浪費記憶體去存取undefined元素
如以下的code
a[0] = 0;
a[1] = 1;
a[2] = 2;
那麼三個連續元素是儲存在底層陣列沒錯
存取起來速度會很快
但是以下code
a[0] = 0;
a[10] = 1;
a[12] = 2;
只有a[0]是存在底層陣列
a[10]和a[12]是存在底層的binary search tree
存取起來的效能量級就是跟Object和Dictionary一樣的
再如
a[10000] = 1;
所消耗的記憶體不是10000個Number
而是只有一個Number而已,是用底層的binary search tree在存
所以如果真的要龜毛
你應要一開始把aInverse的所有元素都先初始化成-1或其他值
才可以真正得到array效能上的優勢
我記得以上豆知識是在Senocular的blog上看到的 :)
p.s. 我找不到Spare Array 在AS3的底層是以BST實作的證實.
2010年11月10日 星期三
[API Bug] MovieClip Won't Stop on First Frame
碰到一個很詭異的問題,
就是有些movieclip在flex builder 編譯之後執行都正常.
但是export成AIR時, 這些movieclip 並沒有在預期中停在first frame.
(即在.as中做的初始化動作 mc.gotoAndStop(1) 這個動作是無效的,
但gotoAndStop(n), n != 0, 卻是有效的!!)
但若在.fla中將這些movieclip的第一個frame中加上 stop()指令,
它們會正確停下來, 但這造成在控制播放時的困擾.
找了一個小時的bug, 最後發現原來有下面這個issue
http://www.actionscript.org/forums/showthread.php3?t=156151
簡單的說, 就是movieclip在加入stage前,
gotoAndStop(1)是無法讓它停在first frame的.
但原因不詳.
就是有些movieclip在flex builder 編譯之後執行都正常.
但是export成AIR時, 這些movieclip 並沒有在預期中停在first frame.
(即在.as中做的初始化動作 mc.gotoAndStop(1) 這個動作是無效的,
但gotoAndStop(n), n != 0, 卻是有效的!!)
但若在.fla中將這些movieclip的第一個frame中加上 stop()指令,
它們會正確停下來, 但這造成在控制播放時的困擾.
找了一個小時的bug, 最後發現原來有下面這個issue
http://www.actionscript.org/forums/showthread.php3?t=156151
簡單的說, 就是movieclip在加入stage前,
gotoAndStop(1)是無法讓它停在first frame的.
但原因不詳.
2010年11月5日 星期五
2010年11月4日 星期四
Performance Killer: Alpha and Blend Mode
以下截錄自一個adobe 工程師的blog
http://www.kaourantin.net/2005/09/some-word-on-blend-modes-in-flash.html
Some word on blend modes in Flash Player 8
Blend modes is one of those features who were long thought impossible to do in the Flash Player. And to be frank, it was indeed the most difficult feature I worked on during this release. Something to understand here is that blend modes are not implemented through the bitmap caching feature like the filters, but it's actually part of the core vector renderer. The two main advantages here are that using blend modes will not use excessive amounts of memory and use the shortest path possible in the rendering pipeline making it acceptable speed wise.
Nevertheless there are some things which need to be understood about this feature. It has limitations performance wise. In fact anytime you use a blend mode, all of the vector content in a particular region of your movie will be handled as it was partially transparent. And as you might know using transparent vectors can be a bit slow if used too graciously. Experiment and see where they are useful, but do not overuse them. Sometimes precompositing or using bitmap caching might help.
以下轉自adobe 官方論壇
Alpha blending
http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36c11f3d612431904db9-7ffe.html
Avoid using effects that require alpha blending when using the alpha property, such as fading effects. Keep in mind that alpha blending is processor-intensive for Flash Player and can hurt performance on slow devices.. Avoid using the alpha property, when possible.
http://www.kaourantin.net/2005/09/some-word-on-blend-modes-in-flash.html
Some word on blend modes in Flash Player 8
Blend modes is one of those features who were long thought impossible to do in the Flash Player. And to be frank, it was indeed the most difficult feature I worked on during this release. Something to understand here is that blend modes are not implemented through the bitmap caching feature like the filters, but it's actually part of the core vector renderer. The two main advantages here are that using blend modes will not use excessive amounts of memory and use the shortest path possible in the rendering pipeline making it acceptable speed wise.
Nevertheless there are some things which need to be understood about this feature. It has limitations performance wise. In fact anytime you use a blend mode, all of the vector content in a particular region of your movie will be handled as it was partially transparent. And as you might know using transparent vectors can be a bit slow if used too graciously. Experiment and see where they are useful, but do not overuse them. Sometimes precompositing or using bitmap caching might help.
以下轉自adobe 官方論壇
Alpha blending
http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36c11f3d612431904db9-7ffe.html
Avoid using effects that require alpha blending when using the alpha property, such as fading effects. Keep in mind that alpha blending is processor-intensive for Flash Player and can hurt performance on slow devices.. Avoid using the alpha property, when possible.
訂閱:
文章 (Atom)