Domanda

In my main application I have a result event and an XMLList, which is filled with my results. The XMLList is defined outside of a function like so:

public var testList:XMLList = new XMLList();

But within my result handler it is populated with data from the result and it works fine. I need to create an external component MXML file that will contain a List, but from within that component file I can't access testList from the main application.

I have included xmlns:local="*" in each file and my component file also has the following imports:

import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.core.Application;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;

I don't understand what I'm doing wrong.

È stato utile?

Soluzione

You need to pass the testList as a property of your component.

Main - you have the testList from your result event and your custom component. Pass the testList to a property you've defined in the component, such as data:

<?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"
               xmlns:local="*">

    <fx:Script>
        <![CDATA[
            [Bindable]
            public var testList:XMLList = new XMLList();
        ]]>
    </fx:Script>

    <local:CustomComponent data="{testList}" />

</s:Application>

CustomComponent - from the component you created, access the testList from a property, such as data in this example:

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            [Bindable]
            public var data:XMLList;
        ]]>
    </fx:Script>

    <s:List dataProvider="{new XMLListCollection(data)}" />

</s:Group>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top