0

could anyone please help me. My problem is that I am using a variable to identify an element section of the many galleries I have under the tag "galleryType" and nothing is returning for me to display. Am I searching for my galleryType the right way in my code or do I need to loop through my galleryTypes on my XML. thanks in advance.

here is my xml code:

<My_gallery>
    <galleryType Name="GalleryName001">
        <images>
            <image label="example text" thumb_src="folder/thumb001.jpg">folder/image001.jpg</image>
            <image label="example text" thumb_src="folder/thumb002.jpg">folder/image002.jpg</image>
            <image label="example text" thumb_src="folder/thumb003.jpg">folder/image003.jpg</image>
        </images>
    </galleryType>
    <galleryType Name="GalleryName002">
        <images>
            <image label="example text" thumb_src="folder/thumb001.jpg">folder/image001.jpg</image>
            <image label="example text" thumb_src="folder/thumb002.jpg">folder/image002.jpg</image>
            <image label="example text" thumb_src="folder/thumb003.jpg">folder/image003.jpg</image>
        </images>
    </galleryType>
</My_gallery>

Here is my as3 code:

public function selectGallery(val:String):void {
    galleryName = val;
    navClass = new navigationClass(galleryName);
    galleryName = navClass.getGalleryType;
    loadXML("myGallery001.xml");
}

private function loadXML(img_source:String):void {
    xmlData = new XML();
    xmlData.ignoreWhitespace = true;
    xmlLoader = new URLLoader();
    xmlLoader.load(new URLRequest(img_source));
    xmlLoader.addEventListener(Event.COMPLETE, XMLloaded);
}

private function XMLloaded(evt:Event):void {
    xmlData = new XML(evt.target.data);     

    // I am getting a result back with my trace but nothing is going into my imgList
    imgList = xmlData.galleryType.(@Name==galleryName).images.*;
    trace(xmlData.galleryType.(@Name == galleryName).images.*);
}images
6
  • Are you sure of the value contain into galleryName, into evt.target.data ? Commented Feb 4, 2011 at 18:57
  • evt.target.data holds only my XML. galleryName is a public variable, is this what your mean? Commented Feb 4, 2011 at 19:52
  • Can you trace what is the content of galleryName and evt.target.data when into XMLloaded Commented Feb 4, 2011 at 19:56
  • thanks for the reply. I am sorry I couldn't back to you earlier. Yes my traces on galleryName returns the gallery name for the specific elements I am trying to pull from my xml, and a trace on evt.target.data returns my xml doc. I don't get why my variable is not recognized when I try to assign the gallery type and it's sub-nodes to the imgList XMLList class object. Commented Feb 5, 2011 at 11:09
  • what is imgList data type, where is it declared and is it created/initialized? Commented Feb 5, 2011 at 17:16

2 Answers 2

1

try imgList = new XMLList(new XML(xmlData.galleryType.(@Name == galleryName).images.* as String));

Sign up to request clarification or add additional context in comments.

Comments

0

I would go for looping, that way you have more control over the values that passes in the loop.

example:

var thumbArray = new Array();

function processXML(evt:Event):void
{
     galleryXML = new XML(evt.target.data);
     for each (var i:XML in galleryXML.files.file)
     {
          thumbArray.push(i.thumbnail);
     }
}

then you can bind the Array to your List or DataGrid, also changing an Array to reflect changes in your List or other object is easier to control, if made [Bindable] it will reflect changes to the array to the Object onto which it is connected.

3 Comments

wilfred thanks for the reply. I am not sure what you mean in your code example. Even if I push all my nodes (which is my gallery type) and subnodes to an array call thumbArray, I still wouldn't be able to reach my subnodes of the gallery types I want.
well the example was purely meant as an example to loop through an XML object, if you need more levels i would suggest using an ArrayCollection and filling them up with Array's. Then you can reach all subnodes as well. I was merely pointing you in a direction to decide between your way described in your question, and using a loop. You can find info on ArrayCollection here: link.
Hey Wilfred. Thanks for the comment. I haven't read much on ArrayCollection but it does should like the right track from here. I misunderstood how I could use your example that would filter out the right node and it's subnodes before but I will be using that formula. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.