PDA

View Full Version : How to send Bindable String as parameter to a function


frasseff
01-03-2009, 08:39 PM
Hi all
I have a Bindable string from a Class Ihave made. I want to send it as prameter to a function in my mxml file. How can I do that ?

I am doing the following but it is not working ("initApp('{mypara}')").


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" xmlns:components="components.*" applicationComplete="initApp('{mypara}')">

<mx:Binding source="dipclasses.conf.GETALLLANDPOLY" destination="mypara" />
<mx:Script>
<![CDATA[
import dipclasses.conf
[Bindable]
public var mypara:String;
public function initApp(method:String): void
{


var netConnection:NetConnection = new NetConnection();
netConnection.connect(conf.URL);

var responder:Responder = new Responder(onComplete, onFail);
netConnection.call(method, responder);
}
function onComplete(results) {
var res:Object= results;
//UserMessage.text += results;
for (var r:Object in res)
{
UserMessage.text += r + res[r];
}
}

function onFail(results) {
for each (var thisResult in results){
UserMessage.text += thisResult;
}
}

private function mapMousOver(event:MouseEvent):void
{
var cor:String;
cor = "X: " + event.localX.toString() + " Y: " + event.localY.toString() + "\n";
CommandMessage.text += cor;
}

]]>
</mx:Script>

<mx:HBox x="0" y="0" width="100%" height="100%" backgroundColor="#050505" color="#EDF5F7">
<mx:VBox>
<mx:Image id="map" source="images/standard.gif" mouseMove="mapMousOver(event)" click="mapMousOver(event)"/>
<mx:HBox>
<mx:RichTextEditor title="Message To Player" height="273" width="336"
color="#790404" fontWeight="bold"
headerColors="[#e4e4e0,#eeeeee]"
footerColors="[#eeeeee,#e4e4e0]">
</mx:RichTextEditor>
<mx:VBox>
<components:userList/>
</mx:VBox>
</mx:HBox>
</mx:VBox>
<mx:VBox>
<mx:Label text="Move Command:" fontWeight="bold" />
<components:orderBox/>
<mx:TextArea id="CommandMessage" width="496" height="201" color="#790404" />
<mx:Button label="Send order" width="496" click="initApp('{mypara}')"/>
<mx:Label text="New Units :" fontWeight="bold" />
<mx:HBox>
<mx:Image source="images/ab-40.gif"/>
<mx:Image source="images/ch_b1_bis.gif"/>
</mx:HBox>
<mx:Label text="News :" fontWeight="bold" />
<mx:TextArea width="503" height="46" color="#790404" />
<mx:Label text="User Message:" fontWeight="bold" />
<mx:TextArea id="UserMessage" width="506" height="212" color="#790404" />
</mx:VBox>
</mx:HBox>

</mx:Application>



My class look like this


package
{
public class conf
{
public static var URL:String = "MyURL";
public static var METHODPREFIX:String = "exposed.";
[Bindable]
public static var GETALLLANDPOLY:String= METHODPREFIX + "getAllLandpoly";
public function conf()
{
}

}
}


Thanx
Frasse

wvxvw
01-03-2009, 09:24 PM
First, answering your question: whatever follows applicationComplete="... should be an event handler, so, you cannot pass strings there likewise anything else which is not an event.
But, being honest I don't understand why do you need to pass it in the arguments. It would be much more convenient to access it from the even handler.
Add to this: the names of classes (and only classes!) must start with the capital letter, functions must have return type, functions arguments must be typed, the type of iterator in for-in loop is String and not Object, functions must have access modifier etc...

frasseff
01-03-2009, 10:13 PM
Thanx wvxvw for your replay.
I am new in the flex world thats why my code not follow flex code rules . I am trying to organazie my code to have some config class use all static value. I have solve the problem now by accessing static method in class like this initApp(conf.GETALLLANDPOLY) and it is work. What I really need is some config read facility as ini file reader but in flex I have to write parser. do you know if any standard way in flex to access config file ?
Thanx

wvxvw
01-03-2009, 11:07 PM
Usually ini files are simple text files... but there's no special format for them. I'd say that you can use whatever format you want to pass your configuration settings to the program. If you need it to be more comprehensible, I'd arrange the data inside the ini file into XML structure, if you need it to be more efficient, I'd use ByteArray...

ljuwaidah
01-04-2009, 08:39 AM
i do it this way, it might not apply to your case but you can figure something out, if you do, please post it here.

<mx:TextArea text="{initApp(mypara)}"/>