5

In flex builder 4.6,am trying to bind data from am sql query, showed in a <s:List> with an item renderer <s:Textarea>

My Code as follows:

<s:List id="listapagar" x="304" y="276" width="330" height="42" borderVisible="false"
        color="#FF0000" dataProvider="{dataProvider}" enabled="false" fontSize="22"
        fontStyle="italic" fontWeight="bold" labelField="nome" textAlign="center"
        textDecoration="underline">
    <s:itemRenderer>
        <fx:Component>
            <s:ItemRenderer>
            <s:TextArea id="apagar" width="330" height="42" text="R$ {data.valorapagar}" />      
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>
</s:List>

and here, my sql, displayed trough the <s:list> :

protected function buttonX():void
        {
            var sqlConnection:SQLConnection = new SQLConnection();
            sqlConnection.open(File.applicationDirectory.resolvePath("testeDb.sqlite"));

            var stmt:SQLStatement = new SQLStatement();
            stmt.sqlConnection = sqlConnection;
            stmt.text = "SELECT * FROM comandatual order by numerodatransacao desc limit 1 ";
            stmt.execute();

            dataProvider = new ArrayCollection(stmt.getResult().data);
        }

after it , i trying to take the result showed at the s:TextArea id="apagar" and bind with another text area, to perforn a simple minus calc, like this :


<fx:Binding source="apagar.text" destination="restroco.text"/>

<fx:Model id="Calculos" >

        <Calculos>
            <!-- Perform a calculation. -->
            <a>{(Number(restroco.text)) - 3}</a>
            </Calculos>
    </fx:Model>

but at this time, flex return an error that cannot let me advance :

1120: Access of undefined property apagar. Flex Problem


so, i'm get stucked, if anyone want to see my full code, they are here :

http://freetexthost.com/srxslotf1x

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
  • 1
    `apagar` is only known in the scope of your inline component (the itemRenderer of `listapagar`). You cannot simply access it outside that scope; there are many instance of `apagar`; which one would you be binding to? If you tell us what you're trying to achieve, maybe I can help you fix it. – RIAstar Oct 18 '12 at 15:58
  • thanks for you advise, i need exactly bind the textarea "apagar". any method to transfer the data from then to any other part of the software ? they use the dataprovider of the s:list "listapagar" if only i can put the dataprovider to show the data into an s:Textarea instead to be forced to show in an S:list, but aways i try to change the componente an error occurs. – Geth With Doubt Oct 18 '12 at 23:00
  • I'm sorry. I don't understand much of what your saying. `Transferring data to any other part of the software` is usually done through the use of events. However if you only wish to show some content of the currently selected item in your TextArea, then you can simply bind to the properties of `listapagar.selectedItem`. – RIAstar Oct 18 '12 at 23:06
  • plz, do you can provide am sample code ? i want to understand the proposited use of "listapagar.selectedItem" – Geth With Doubt Oct 19 '12 at 15:31
  • 3
  • thanks, going to try and report the results after the debuggin , thanks for the help. – Geth With Doubt Oct 22 '12 at 01:42
  • 2
    you can also access main file defnitions from inside `` with `outerDocument`, however, `selectedItem` is definitely better idea than allowing your renderer to know about surrounding scope. – user1875642 Dec 22 '12 at 17:43

1 Answers1

0

As @RIAStar explained, your fx:Model can't access apagar. In addition to the suggested solution, you could also use the IndexChangeEvent:

<fx:Script>
    <![CDATA[
        import spark.events.IndexChangeEvent;

        private var apagarNum:Number = NaN;

        protected function selectionChangedHandler(event:IndexChangeEvent):void
        {
            apagarNum = Number(listapagar.selectedItem.valorapagar);
        }

    ]]>
</fx:Script>

<fx:Model id="Calculos" >
    <Calculos>
        <!-- Perform a calculation. -->
        <c>{(Number(restroco.text)) - 3}</c>
        <!-- calcular com valor a pagar -->
        <d>{apagarNum - 3}</d>
    </Calculos>
</fx:Model>

<s:List id="listapagar" change="selectionChangedHandler(event)" ...>
Brian
  • 3,850
  • 3
  • 21
  • 37