开发者

reading variable from xml file in flex

I'm trying to read the address of a flv file from an xml file and then put it in the "source" property of a videodisplay tag . here's my code :

//in decleration tags
<fx:Model id="myModel" source="myXML.xml"/>
<s:ArrayList id="myArrList" source="{myModel.main}"/>

//in the main code
<mx:VideoDisplay id="videoDisplay" source="{myArrList.getItemAt(0)}" />
开发者_Python百科

and the xml file is:

<main>
<myFile>"g:\myflv.flv"</myFile>
</main>

anyone knows what's wrong? tnx


For now, this will work :

//in decleration tags
<fx:Model id="myModel" source="myXML.xml"/>

//in the main code
<mx:VideoDisplay id="videoDisplay" source="{myModel.mainFile as String}" />

However, if you add more tags in your XML, it will not work anymore. You Model instance is actually an ObjectProxy instance. If there is one tag, the Flex framework will create an ObjectProxy with a myFile property that is a String. If there are more than one tag, the myFile property will be an Array.

So, If you really want to use an ArrayList instance, you won't have any other choice than doing something similar to :

<?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" minWidth="955" minHeight="600"
               applicationComplete="application1_applicationCompleteHandler(event)"
               >
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function application1_applicationCompleteHandler(event:FlexEvent):void
            {
                if (myModel.myFile is Array)
                    myArrList = new ArrayList(myModel.myFile)
                else
                    myArrList = new ArrayList([myModel.myFile]);
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <fx:Model id="myModel" source="myXML.xml" />
        <s:ArrayList id="myArrList" />
    </fx:Declarations>


</s:Application>

Also, have you installed the debug version of Flash Player?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜