2012-07-25 167 views
0

我目前正在嘗試將一個簡單的Illustrator插件放在一起,並且來自設計背景,這被證明是一項非常艱鉅的任務,我對JS有經驗,但對Flex沒有經驗。從Textinput傳遞給控制器​​文件

我想要做的是在Illustrator中有一個面板,帶有一個輸入欄和一個按鈕。您在輸入中輸入內容並按下按鈕,並將具有所需文字的文本框添加到畫布。

但是,如何將mx:Textinput的值傳遞給Controller.as文件?我無法在網上找到答案。

這是我main.mxml文件:

<?xml version="1.0" encoding="utf-8"?> 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false"> 
    <mx:Script> 
     <![CDATA[ 
      private var c:Controller = new Controller(); 
     ]]> 
    </mx:Script> 

    <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center"> 
     <mx:Label text="myVariable"></mx:Label> 
     <mx:TextInput name="TextValue"/> // I want the text value to be passed to the Controller class so I can pass it on to my JSX function 
     <mx:Button label="Run" click="c.run()"/> 
    </mx:VBox> 

</mx:Application> 

這是我Controller.as文件:

package 
{ 
    import flash.external.HostObject; 

    public class Controller 
    { 
     [ Embed (source="myScript.jsx" , mimeType="application/octet-stream")] 

     private static var myScriptClass:Class; 

     public function run():void { 
      var jsxInterface:HostObject = HostObject.getRoot(HostObject.extensions[0]); 
      jsxInterface.eval(new myScriptClass().toString()); 

      //calling from AS to JSX 
      jsxInterface.myJSXFunction (myVariable); //This is where I want the value to be passed to 

     } 

    } 
} 

回答

1

您也可以直接將字符串傳遞到c.run()調用。

public function run(myString:String):void { 
... 
    jsxInterface.myJSXFunction (myString) 
... 

然後

<mx:TextInput id="TextValue"/> 
<mx:Button label="Run" click="c.run(TextValue.text)"/> 

只是另一種方法。

Loic

+0

Thx求救! :) – timkl 2012-07-28 18:08:56

1

首先聲明公共財產public var myTextValue : String;在你的控制器。

然後聲明雙向在MXML結合<mx:TextInput text="@{c.myTextValue}"/>

現在你有myTextValue屬性總是包含實際值。

但是很久以前就引入了雙向綁定。

或者,你可以添加一個change事件偵聽器,您TextInput實例<mx:TextInput id="myTextInput" change="c.myTextValue = myTextInput.text"/>