我想将.mxml中的字符串传递给.as类..因为我尝试使用[Bindable] ..但是我
只获取null值。如何从mxml中获取字符串?
I have given the link to show u what i have tried:
http://192.150.16.67/devnet/flex/articles/databinding_pitfalls.html
答案 0 :(得分:1)
请找到以下代码,这可以帮助您解决问题。
<强> Main.mxml 强>
<?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">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var stringReaderObject:StringReader;
private function clickHandler():void
{
if(!stringReaderObject)
{
stringReaderObject = new StringReader();
}
stringReaderObject.readString = inputTextID.text;
}
]]>
</fx:Script>
<s:Group x="50" y="50">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:TextInput id="inputTextID"/>
<s:Button label="Click" click="clickHandler()"/>
</s:Group>
</s:Application>
班级名称: - StringReader.as
package
{
public class StringReader
{
private var _readString:String;
public function StringReader()
{
}
public function set readString(value:String):void
{
_readString = value;
trace(_readString);
}
public function get readString():String
{
return _readString;
}
}
}
trace将确定如何将值从MXML传递到.as类。
可以通过以下两种方式实现: -
1)通过在您的类中创建公共变量。 2)在您的应用程序中创建全局并在您的班级中访问它。
希望这对你有所帮助。