-
1. Re: unable to access item in xmlListCollection...
David_F57 Dec 11, 2009 10:29 PM (in response to cyber0897)Hi,
When you retrieve your item you have 3 'root' levels, images,video, navbutton
so
mytext.text = navControl[2]['next'] will return "MORE OPTIONS";
the 3rd root in the xml is <navButtons> which is navControl[2] then you select the tag ['next'].
hope this helps
David.
-
2. Re: unable to access item in xmlListCollection...
cyber0897 Dec 14, 2009 1:46 PM (in response to David_F57)hey david.. that worked like a champ!
the only thing is... in the future, there is a possibility that we might have to mess with the xml, and writing [2] and [3] in the statement seems pretty static dosen't it? is there any other way around it? to have somehting like navControls.multiPage or somehting to that effect??
-
3. Re: unable to access item in xmlListCollection...
David_F57 Dec 14, 2009 6:06 PM (in response to cyber0897)Hi,
I'm not sure that this is the best way to do things but it works , (i'm not a big user of xml)
So by iterating through the nodes you can get the index of the node that matches your tag, i think that there is also a method getindex using qnames but i would need to have a look at that to see how it works.
protected function myXML_resultHandler(event:ResultEvent):void
{
var myNode:String="navButtons"
ReturnedXML.source = event.result[0].children();
lbl.text=String(getNode(ReturnedXML,node));
}
private function getNode(listname:XMLListCollection,nodeName:String): int
{
var result:int=0;
for (var i:int=0; i < listname.length;i++)
{
var currentNode:XML = ReturnedXML[i];
if (currentNode.localName().toString()=='navButtons') result = i;
}
return(result);
}
-
4. Re: unable to access item in xmlListCollection...
David_F57 Dec 14, 2009 6:19 PM (in response to David_F57)hi,
Just one thing, maybe its a 'root' level thing or even a bug but i would have expected
myxmllist['navButtons']['Multipage'] to work but it crashes out the property iteration routines in the ListCollectionView file.
maybe time for one of the Adobe guys to have a look , if its a bug i'll raise it, if its expected behaviour its not good as a crash should never be caused in this instance.
David
-
5. Re: unable to access item in xmlListCollection...
Peter deHaan Dec 14, 2009 6:57 PM (in response to David_F57)Not sure if I'm following the thread 100%, but here's a few suggestions...
If you can crash Flash Player, please file a bug ASAP with a test case. Send me the bug number and I can try and get the bug investigated right away. You should never be able to crash Player. Ever.
As for the XML/E4X issue, this seemed to work for me:
<?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"> <fx:Script> <![CDATA[ protected function button1_clickHandler(evt:MouseEvent):void { if (dat.navButtons.multiPages == "true") { gr.visible = true; backLbl.label = dat.navButtons.back.text(); nextLbl.label = dat.navButtons.next.text(); } else { gr.visible = false; } } ]]> </fx:Script> <fx:Declarations> <fx:XML id="dat" xmlns=""> <item label="Arm/Disarm System"> <images> <img url="modules/apx32/images/APX32-armDisarm_01.png" details="true"> <buttons hasButtons="true"> <button name="CLICK HERE" posX="513" posY="253" /> </buttons> </img> <img url="modules/apx32/images/APX32-armDisarm_02.png" details="false"> </img> <img url="modules/apx32/images/APX32-armDisarm_03.png" details="true"> <buttons hasButtons="true"> <button name="CLICK HERE" posX="530" posY="170" /> </buttons> </img> <img url="modules/apx32/images/APX32-armDisarm_04.png" details="true"> <buttons hasButtons="true"> <button name="CLICK HERE" posX="510" posY="152" /> </buttons> </img> </images> <video> <videoPresent>true</videoPresent> <img url="" /> </video> <navButtons> <multiPages>true</multiPages> <next>"MORE OPTIONS"</next> <back>"BACK"</back> </navButtons> </item> </fx:XML> </fx:Declarations> <s:VGroup> <s:Button label="get navButtons stuff" click="button1_clickHandler(event)" /> <s:HGroup id="gr"> <s:Button id="backLbl" /> <s:Button id="nextLbl" /> </s:HGroup> </s:VGroup> </s:Application>
If I click the first button it digs down into the XML and grabs the <next> and <back> text nodes. If mutiPages is "true", it sets two button labels. If multiPages is "false" (or more specifically not the string "true" -- which it would never be since I hardcoded that XML packet), then it'd hide the buttons by setting the HGroup container's visible property to false.
Peter
-
6. Re: unable to access item in xmlListCollection...
David_F57 Dec 14, 2009 7:47 PM (in response to Peter deHaan)Hi,
Its a matter of 'forest for the trees', i kept looking at xmllistcollection instead of just an xml document(the reason another set of eyes do the trick)
so kiss all the BS goodbye and just use an xml document.
protected function myXML_resultHandler(event:ResultEvent):void
{
myXMLSource = event.result[0];
trace(myXMLSource.navButtons.next);
}
<fx:Declarations><fx:XML id="myXMLSource" xmlns=""/><s:HTTPService id="myXML" url="myxml.xml" resultFormat="e4x"result="myXML_resultHandler(event)" fault="myXML_faultHandler(event)"/></fx:Declarations>@Peter-the player doesn't crash just the call fails , I will file a bug becuase I think that with xmllistcollection you should be able to drill down using tag names.David. -
7. Re: unable to access item in xmlListCollection...
SunilAdobeDec 14, 2009 10:59 PM (in response to cyber0897)
If you are enrolled in the pre-release you could also try out the new feature import from XML files, which will basically allow you to work with action script objects instead of you trying to access the nodes using e4x.
If you are not in pre-release, you could still try using it by using it in connect to HTTP service. DCD features in FB4 comes with a default XML deserializer (as part of serializers.swc) that will convert your XML to strong AS objects.
Thanks
-Sunil
-
8. Re: unable to access item in xmlListCollection...
cyber0897 Dec 18, 2009 2:52 PM (in response to David_F57)hey david, so would the myXMLSource be of type "XMLDocument"?
becuase, i tried doing that, and i get the following error
"Error #1034: Type Coercion failed: cannot convert XML@393dae21 element <menu> to flash.xml.XMLDocument."
-
9. Re: unable to access item in xmlListCollection...
David_F57 Dec 18, 2009 8:16 PM (in response to cyber0897)Hi,
The myxmlsource is declared as XML
David.