我有一個帶有tabnavigator和textarea的創建字符組件。在我的主應用程序中,我想將textarea id --mainchar文本保存到標記中。我試過dotnotation,沒什麼,我試過import components.CreateCharacter;仍然沒有,並嘗試在網絡上發現一些其他的選擇,但不能得到這個工作。在單獨的組件文件中綁定到textarea.text
注意,代碼工作正常,如果我打電話的主要應用組件,所以代碼工作正常,它是在組件文件夾中的成分(CreateCharacters)只是調用。組件文件夾位於src文件夾中。下面是代碼:
Main.mxml
<fx:Script>
<![CDATA[
import components.CreateCharacters
[Bindable]
public var xmlData:XML=<ROOTS></ROOTS>;
public function sav_clickHandler(event:MouseEvent):void
{
var fr:FileReference = new FileReference();
var ba:ByteArray = new ByteArray();
var newXmlRow:XML=<ROOTS>
<TXT>{components.CreateCharacters.mainchar.text}</TXT>// The problem lies with this line
<TXTA>{txt2.text}</TXTA>
<DTF>{txt3.text}</DTF>
</ROOTS>;
ba.writeMultiByte(newXmlRow, 'utf-8');
fr.save(ba);
}
private var openedFile:File;
private function open_clickHandler(event:MouseEvent):void {
openedFile = new File();
openedFile.addEventListener(Event.SELECT, file_select);
openedFile.browseForOpen("Please select a file...");
}
private function file_select(event:Event):void {
if(openedFile != null && openedFile.exists){
var fileStream:FileStream = new FileStream();
fileStream.open(openedFile, FileMode.READ);
var readXML:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
fileStream.close();
trace(readXML.toString());
CreateCaracters.maichar.text = readXML.TXT;
txt2.text = readXML.TXTA;
txt3.text = readXML.DTF;
}
trace(event);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<net:FileReference id="fileReference" />
</fx:Declarations>
<s:Image x="0" y="0" width="100%" height="50" scaleMode="stretch"
source="assets/imaginationFly.png"/>
<s:Image x="12" y="1" source="assets/ECWDove.png"/>
<mx:TabNavigator x="1" y="49" width="100%" height="100%" backgroundColor="#7EB7C5"
chromeColor="#85B5BF">
<s:NavigatorContent width="100%" height="100%" label="Start">
<s:TextArea id="txt2" x="57" y="29"/>
</s:NavigatorContent>
<s:NavigatorContent id="Characters" width="100%" height="100%" label="Characters">
<components:CreateCharacters id="creatchr" width="100%" height="100%"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="Worlds">
<s:TextArea id="txt3" x="55" y="10"
text="hello
I am testing this shit
hope it works"/>
<s:Button id="sav" x="285" y="138" label="Save" click="sav_clickHandler(event)"/>
<s:Button id="open" x="381" y="138" label="Open" click="open"/>
等等
CreateCharaters.mxml(組件)
<?xml version="1.0" encoding="utf-8"?>
<s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
chromeColor="#0106BD" paddingLeft="10" paddingRight="0">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ViewStack id="Characters" x="172" y="10" width="81" height="100%" backgroundColor="#030BB3"
chromeColor="#D7D7D8" paddingLeft="5" paddingRight="15">
<s:NavigatorContent id="Hero" width="100%" height="95%" label="Main Charater">
<s:HGroup width="100%" height="100%">
<s:TextArea id="mainchar" bottom="0" width="80%" height="100%"
chromeColor="#7070FD">//this is the textarea I want to use
<s:text><![CDATA[
Name:
Surname:
Nickname:
Hair Color:
等等
任何幫助,請
感謝您的答案,但變量var currentText stil給了我一個未定義的屬性在mainchar.text。它會讀取CreateCharacter位,但會在mainchar位上給出未定義的錯誤。我不明白爲什麼它沒有選擇它。難道是因爲mainchar在tabnavigator? –
不確定'TabNavigator'是如何工作的,但由於您沒有指定任何'itemCreationPolicy','creatchr'應該存在。你得到的錯誤究竟是什麼? –
確定它使用了id而不是文件名。但現在,當我運行應用程序時,出現#1009錯誤,無法訪問空對象引用的屬性或方法。再次卡住 –