由於某些原因,這個flex 4代碼給了我一個錯誤,但我找不出原因。在我WindowedApplication
我:Flex 4/WindowedApplication的空氣設置邊界
var prefs:Object = fs.readObject();
fs.close();
var rect:Rectangle = new Rectangle();
rect = prefs.bounds as Rectangle;
this.bounds = rect; // error here
Error message: ArgumentError: Error #2007: Parameter rect must be non-null.
我本來也試了一下沒有RECT對象,只是做:
this.bounds = prefs.bounds as Rectangle;
使我有以下錯誤:
TypeError: Error #1034: Type Coercion failed: cannot convert [email protected] to flash.geom.Rectangle.
這似乎是一個虛假的錯誤,因爲我可以分配pref.bounds rect沒有錯誤。我不知道爲什麼這不起作用。它在flex 3兼容模式下工作,但也打破了我的許多spark組件,所以我不能使用它。
所以你這樣說: this.bounds = rect; 等同於: this.bounds = null; 而windowedApp不接受? 當我使用調試器時,prefs.bound具有您期望的所有字段,寬度,高度,x,y等。因此,如果它不是矩形,我不知道它會是什麼。 通過這種方式的prefs對象實際上是從this.bounds最初生成並保存到一個文件。這就是爲什麼當我用這段代碼讀回來的時候,我感到很驚訝,它就像這樣窒息。 – solerous 2010-07-09 18:28:07
@solerous看到我的更新。 – Amarghosh 2010-07-10 04:57:19
嘿謝謝你的迴應。不幸的是,代碼不起作用。 var rect:Rectangle = Rectangle(fs.readObject()); (rect); trace(rect); 給我錯誤: TypeError:錯誤#1034:類型強制失敗:無法將Object @ 1db7bdf9轉換爲flash.geom.Rectangle。儘管我使用: registerClassAlias(「flash.geom.Rectangle」,Rectangle); fs.writeObject(this。邊界); 最初保存它。 我只是不明白爲什麼AIR不能做這種1:1轉換。這段代碼實際上是從Flex 3中的應用程序中獲取的,並且在那裏完美運行。我只是不知道Flex 4中發生了什麼變化。 – solerous 2010-08-02 20:20:33