dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: XML object data dosen't show up

  1. #1
    Genius on Demand
    Join Date
    Oct 2005
    Location
    Brandon, Fl
    Posts
    24

    XML object data dosen't show up

    i am having trouble accessing XML data once it has been brought into Flash. i use this AS:


    stop ();
    //creates new XML object
    var playlistXML:XML = new XML ();
    //parses XML file to eliminate erroneous white space
    playlistXML.ignoreWhite = true;
    //creates function to loop and populate an
    //array with info contained in the XML file
    playlistXML.onLoad = function () {
    //creates array that the list item will use
    var tempArray = new Array ();
    //begin the loop using the length of the children in the XML file
    for (var i = 0; i this.firstChild.childNodes.length; ++i)
    {
    //creates a new menu item that will contain an array of values
    tempArray[i] = new Object ();
    tempArray[i].clipID = this.firstChild.childNodes[i].attributes.clipID;
    tempArray[i].clipTitle = this.firstChild.childNodes[i].attributes.clipTitle;
    tempArray[i].clipPath = this.firstChild.childNodes[i].attributes.clipPath;
    tempArray[i].replayClip = this.firstChild.childNodes[i].attributes.replayClip;
    tempArray[i].pauseEnd = this.firstChild.childNodes[i].attributes.pauseEnd;
    tempArray[i].pauseTime = this.firstChild.childNodes[i].attributes.pauseTime;

    //trace to see if variables are coming in correct
    trace ("clipID:"+tempArray[i].clipID+" clipTitle:"+tempArray[i].clipTitle+" clipPath:"+tempArray[i].clipPath+" replayClip:"+tempArray[i].replayClip+" pauseEnd:"+tempArray[i].pauseEnd+" pauseTime:"+tempArray[i].pauseTime);
    }
    };
    playlistXML.load ("videoXml.xml");


    and the trace returns:

    clipID:A clipTitle:rock the hula pt.3: 09/08/05 clipPath:media/hula3.flv replayClip:true pauseEnd:true pauseTime:45

    which is the correct information. however if i try to access the same info by placing this trace:

    Code:
    i=0
    trace ("clipID:"+tempArray[i].clipID+"  clipTitle:"+tempArray[i].clipTitle+"  clipPath:"+tempArray[i].clipPath+"  replayClip:"+tempArray[i].replayClip+"  pauseEnd:"+tempArray[i].pauseEnd+"  pauseTime:"+tempArray[i].pauseTime);
    outside of the "onLoad function" i get this:

    clipID:undefined clipTitle:undefined clipPath:undefined replayClip:undefined pauseEnd:undefined pauseTime:undefined

    my question is: how do i access the info within the tempArray object i have created?
    Last edited by surfpunk; 10-15-2005 at 01:44 AM.

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    The scope of the xmlOnload is different to the other code, and the tempArray is assigned to a variable inside the onLoad function, which means after that function quits the variable no longer exists.

    Typically you would assign this array to a variable in _global or _root (global is probably better).

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Genius on Demand
    Join Date
    Oct 2005
    Location
    Brandon, Fl
    Posts
    24
    you my friend...are a god. used _global and voila! it worked.

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center