我是一個完整的Flex新手,所以我的啞巴道歉。我搜索了一個答案,但沒有發現任何似乎在做的伎倆。adobe flash buider(flex4):錯誤#2025或錯誤:addChild()在此類中不可用。相反,使用addElement()
我想要做的事:端口這個例子http://www.adobe.com/devnet/air/flex/articles/flex_air_codebase_print.html 到Flash Builder 4
一切似乎是罰款,但一兩件事。當我使用的原代碼爲AIR應用
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="onApplicationComplete()">
<fx:Script>
<![CDATA[
private static const neededForCompilation:AirGeneralImplementation = null;
private function onApplicationComplete():void
{
var can:MainCanvas = new MainCanvas();
this.addChild(can);
can.labelMessage = "Loaded in an AIR Application ";
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>
我得到這個運行時錯誤
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one. at spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableComponent.as:1038]
如果我用替代
this.addElement(can)
代碼;
一切加載很好,但我第一次嘗試按任何按鈕主畫布,我得到以下運行時錯誤的
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller. at flash.display::DisplayObjectContainer/getChildIndex() at mx.managers::SystemManager/getChildIndex()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:1665] at mx.managers.systemClasses::ActiveWindowManager/mouseDownHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\systemClasses\ActiveWindowManager.as:437]
這裏的主畫布
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="init();">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script source="main.as" />
<mx:Label id="lblMessage" text="The UI from the shared Flex app BothCode" x="433" y="112"/>
<s:Button x="433" y="141" click="saveFile();" label="Save File"/>
<s:Button x="601" y="141" click="GeneralFactory.getGeneralInstance().airOnlyFunctionality();" label="Air Only"/>
</s:Application>
超級簡單的代碼
任何幫助將非常感激。並且任何指向如何設置一個可以在Air和Flash中編譯的項目,同時共享相同代碼的指針,全部用於Flex 4,也將受到極大的讚賞。
謝謝!
謝謝菲爾!!! – 2010-07-04 19:54:47
我遇到同樣的確切錯誤。我的區別是我的主畫布已經使用
。還有其他建議嗎? – D3vtr0n 2010-08-02 20:04:52