4 Replies Latest reply on Sep 7, 2010 3:21 PM by willm8655

    When to use data-binding and when to avoid it.

    willm8655 Level 1

       

       

       

      Hi, i've previously been using data binding quite extensively in some round about ways to get my required results. However this approach has been a bit hit and miss and i suspect it is not very fast!

       

      I have a HTTPService and a Component i want to display the data received from the service, at the moment my code looks like this (Sorry for the mess, i'm not sure how you insert code):

       

       

      <?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"

      initialize="handleInit()"

      >

       

       

      <fx:Script>

      <![CDATA[

       

      import mx.rpc.events.ResultEvent;

       

      [

      Bindable] private var data:String;

       

       

      private function handleInit():void {

      service.send();

      }

       

       

      private function handleResult(event:ResultEvent):void {

      data = event.result.toString();

      }

       

      ]]>

       

      </fx:Script>

       

       

      <fx:Declarations>

       

      <s:HTTPService id="service"

      url="

      myurlhere"

      result="handleResult(event)"

      resultFormat="

      text" />

       

      </fx:Declarations>

       

       

      <s:Label id="label"

      text="

      {data}" />

      </s:Application>

       

       

       

       

       

      I would change to simply assigning the data in the result handler by 'label.text = data' however this will give an error if the label component has not yet been created by the time the service result occurs. Is there a way to avoid using binding in this situation?

       

      Thanks