tags:

views:

49

answers:

1

Hello,

<?xml version="1.0" encoding="utf-8"?>
<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
         title="Monitor" xmlns:plcservicebean="server.services.plcservicebean.*">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.rpc.CallResponder;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            import server.valueObjects.Data;

            [Bindable] 
            public var dbl:Number;
            [Bindable]
            public var val:String;


            public function clientMonitor():void{
                var callResp:CallResponder = new CallResponder();
                callResp.addEventListener(ResultEvent.RESULT, monitorResult);
                callResp.addEventListener(FaultEvent.FAULT, monitorFault);
                callResp.token = plcServiceBean.getMonitorData();
            }

            public function monitorResult(event:ResultEvent):void{
                dbl = event.result.value as Number;
                val = dbl.toString();
                trace (dbl);
                trace(val);
            }

            protected function monitorFault(event:FaultEvent):void{
                Alert.show(event.fault.faultString, "Error while monitoring Data ");
            }
        ]]>
    </fx:Script>
    <s:layout>
        <s:VerticalLayout horizontalAlign="contentJustify" />
    </s:layout>

    <fx:Declarations>
        <plcservicebean:PlcServiceBean id = "plcServiceBean" 
                                       showBusyCursor="true" 
                                       fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"/>
    </fx:Declarations>
    <mx:Form height="103">
        <mx:FormItem label="View" x="2" y="11">
            <s:TextInput id = "view1"
                         text="{val}"/>
        </mx:FormItem>
    </mx:Form>
</s:Panel>

Here the method clientMonitor() is called on creationcomplete() from the main application.

I am not able to bind the Bindable variable dbl to my textInput. Using the debugger, I am able to see that the result is assigned successfully to variable dbl, but it is not able to bind it to the text of view1. I see a NaN displayed in the text of view1.

-H

+2  A: 

You're trying to bind a Number to a String. Try making the types the same and see if that has an effect.

www.Flextras.com
Your code segment in the comment is fairly useless to parse. That said, you don't appear to have a result handler set on your PlcServiceBean class. Should you? Are you sure that the monitorResult is being fired?
www.Flextras.com
Could it be because I am using an event handler for a web service method, executed upon creationComplete(), that I am not able to bind the variable when the method finishes execution?
H P
I have modified the code in the question to incorporate changes suggested.It also reflects my difficult to parse comment above. I am calling the clientMonitor() upon creation complete and upon getting the result monitorResult() is invoked. I am sure that the monitorResult() is being fired, because I can see the trace(dbl) and trace(val) prints the desired result. Variable val fails to bind to the text="{val}". The text remains blank.
H P
Using an event handler to trigger a web service call should have no effect on binding. The code in your original sample is not calling anything upon creationComplete.
www.Flextras.com
I have not posted my main Application. In my main Application, I have a creationComplete which calls the clientMonitor().
H P