Reply LinkBack Thread Tools Search this Thread
Old 13-10-2005, 22:03   #1 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
HELP with XML loading into flash

I have a project where I need to load an images into a movie clips based on urls in that is in an XML file.

Code:
// xml object for xml content (defines sources for selections) var featured_xml = new XML(); featured_xml.ignoreWhite = true; featured_xml.onLoad = function(success){ if (success) trace(this); else trace("Error loading XML file"); // no success? trace error (wont be seen on web) } // load featured_xml.load("xml/fMovies.xml"); var featuredMovie = featured_xml.firstChild.childNodes; featured_mc.loadMovie(featuredMovie[0])

I keep getting this error "Error opening URL "file:///C|/Documents%20and%20Settings/Robert%20McFadden/Desktop/afc/undefined"

saying my var is not defined how do i define this var?
  Reply With Quote
Old 14-10-2005, 04:15   #2 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,728
tricky without seeing the xml structure, but check your path to the nodes and trace(featuredMovie[0]); until you know you are targetting the right data in the xml file
  Reply With Quote
Old 14-10-2005, 10:43   #3 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
Thats the thing, I know that is a proper node, or atleast Im pretty damn sure it is. Can you please tell me if I have my XML structured properly
Code:
- <fMovies> <movie title="Movie Title" url="/movies/movieUrl"> <placeholder image="images/featured/thumbs/thumb1.jpg"/> <caption> video caption </caption> <description type="short"> short description </description> <description type="full"> full description </description> <snapShot> <shot url="path"/> <shot url="path"/> <shot url="path"/> </snapShot> </movie> </fMovies>

Basically I plan on repeating the movie parent over and over to hold info on several movies.
  Reply With Quote
Old 14-10-2005, 11:04   #4 (permalink)
dan
Iris Folder
 
dan's Avatar
 
Join Date: Apr 2003
Location: smokey
Posts: 2,674
You've got two problems

Your calling your loadmovie before your xml has loaded - so it's undefined.

You need to trigger this after the xml load has succeeded. Use a function call from within the onLoad handler...

Your in the right node but you're targeting the node itself not the url attribute.

something like

Code:
var featured_xml = new XML(); featured_xml.ignoreWhite = true; featured_xml.onLoad = function(success){ if (success) { imageIt(); trace(this); }else{ trace("Error loading XML file"); // no success? trace error (wont be seen on web) }; }; // load featured_xml.load("xml/fMovies.xml"); imageIt = function () { var featuredMovie = featured_xml.firstChild.childNodes; trace(featuredMovie); featured_mc.loadMovie(featuredMovie[0].attributes.url); };

When writing things like this always use traces to see where you actually are in the node tree, it's hard to imagine sometimes.

Remember trace(); is your friend. Use it. LOTS.
  Reply With Quote
Old 14-10-2005, 11:23   #5 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,728
just finished typing the same you git
  Reply With Quote
Old 14-10-2005, 11:25   #6 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
you guys fuckin rock. I was about to put a fist thru my monitor.
  Reply With Quote
Old 14-10-2005, 11:27   #7 (permalink)
gray
i still want paying
 
gray's Avatar
 
Join Date: Oct 2003
Location: newcastle, uk
Posts: 4,728
you can also loop through the childNodes using .length

Code:
var featured_xml = new XML(); featured_xml.ignoreWhite = true; featured_xml.onLoad = function(success){ if (success){ allnodes = featured_xml.firstChild.firstChild.childNodes.length; trace("allnodes = "+allnodes); for (i=0; i<allnodes; i++){ featuredMovie = new Array(); featuredMovie[i] = featured_xml.firstChild.childNodes[i].attributes.moviepath; trace(featuredMovie[i]); } } else { trace("Error loading XML file"); // no success? trace error (wont be seen on web) } } featured_xml.load("xml/fMovies.xml");
  Reply With Quote
Old 14-10-2005, 11:30   #8 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
Yea, I have scene all this looping stuff, but can't understand why I would want to use it in the situation. It just seems to me that it would go thru more of the XML file then I want and I don't understand where it is putting the info.

Last edited by d3mcfadden : 14-10-2005 at 12:04.
  Reply With Quote
Old 14-10-2005, 16:01   #9 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
what is wrong with this code??? I am trying to sort thru this array Ive created (or think Ive created) I can trace the entire array, but when I try and call a individual section of it, I get the good old UNDEFINED bullshit?

Code:
function sortMovies(afc_xml) { // start with the first item in the XML var movies = afc_xml.firstChild.childNodes; //trace (movies); for (var i=0; i< movies.length; i++) { // only continue if the type of this item is a squirrel if (movies[i].attributes.series == "featured") { // create variables for our elements featuredSeries = new Array(); featuredSeries[i] = movies[i]; } if (movies[i].attributes.series == "dave") { daveSeries = new Array(); daveSeries[i] = movies [i]; } } }

basically I have two video series I want to sort them out based on their series attribute then put them into their own separate arrays
  Reply With Quote
Old 18-10-2005, 11:49   #10 (permalink)
dan
Iris Folder
 
dan's Avatar
 
Join Date: Apr 2003
Location: smokey
Posts: 2,674
each time your looping your redefining the array. So emptying it.

Define them outside the function then just push(); the entries as they appear to append them to the end of the arrays..

Code:
daveSeries = new Array(); featuredSeries = new Array(); function sortMovies(afc_xml) { // start with the first item in the XML var movies = afc_xml.firstChild.childNodes; //trace (movies); for (var i=0; i< movies.length; i++) { // only continue if the type of this item is a squirrel if (movies[i].attributes.series == "featured") { // create variables for our elements featuredSeries.push( movies[i] ); } if (movies[i].attributes.series == "dave") { daveSeries.push( movies[i] ); } } }

Of course the .push(); appends to the end of the array rather than adding it to a specific location. If that's improtant forget about the push and do it the way you were.
  Reply With Quote
Old 18-10-2005, 11:50   #11 (permalink)
dan
Iris Folder
 
dan's Avatar
 
Join Date: Apr 2003
Location: smokey
Posts: 2,674
Quote:
Originally Posted by gray
just finished typing the same you git

haha
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8