Jump to content


Flash and XML


  • You cannot reply to this topic
8 replies to this topic

#1 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 27 April 2006 - 10:08 AM

Hi, I recently started experimenting XML and Flash to create a photo gallery script.

However, I've hit a deadend with some problems. I have succeeded parsing the XML data in Flash, however, the width of the values are not being parsed correctly.

Here is the code:

depth = 0;
var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
	if (success) {
		var gallery = this.firstChild;
		item_array = gallery.childNodes;
		loadImage();
	}
};
gallery_xml.load("gallery.xml");
function loadImage() {
	attachMovie("mcImage", "image_mc", 5);
	tempMc = image_mc;
	tempMc.bg_mc.fwidth = item_array[depth].childNodes[3].childNodes[0];
	tempMc.bg_mc.onEnterFrame = function() {
		this._width += 5;
		if(this._width>this.fwidth) {
			delete this.onEnterFrame
		}
	};
	tempMc._x = Stage.width/2;
	tempMc._y = Stage.height/2;
	tempMc.empty_mc.createEmptyMovieClip("holder_mc", 10);
	tempMc.empty_mc.holder_mc.loadMovie("data/thumbs/"+item_array[depth].childNodes[2].childNodes[0]);
	tempMc.bg_mc._height = item_array[depth].childNodes[4].childNodes[0]+20;
}

The problem here, is that fwidth is not recognized as a number. Doing a trace commands returns that fwidth is a number, which was parsed from XML. However, flash is not recognizing it in this particular part:
		if(this._width>this.fwidth) {
			delete this.onEnterFrame
		}

Here is the XML File also:
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery>
	<item>
		<title>Work 1</title>
		<date>date 1</date>
		<location>thumb1.jpg</location>
		<width>150</width>
		<height>100</height>
	</item>
</gallery>

Hope someone can help me out! Thanks!

#2 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 27 April 2006 - 10:55 AM

I assume if you do a trace before the if statement that you get the number right?

if not I would change the this.fwidth.. to the full name tempMC.........

#3 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 27 April 2006 - 11:01 AM

hey funkysoul,

thanks for replying. :P

but as I mentioned, the trace DID return correct results. however, the if statement isn't working. why is that so?

Also, if I change:

tempMc.bg_mc.fwidth = item_array[depth].childNodes[3].childNodes[0];

to:

tempMc.bg_mc.fwidth = 300

The if statement works...

#4 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 27 April 2006 - 03:41 PM

hmm..

what about creating your array in the onload section and then accessing it with their corresponding ID's?

have a look at my mp3player tutorial, where I'm using a similar "system".

#5 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 27 April 2006 - 04:05 PM

hmm.. that's not working too.

Is it possible that the values aren't treated as integers but treated as strings instead?

#6 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 27 April 2006 - 04:27 PM

nah.. the problem is that your function is being called once and just once.
and as far as I see you are browsing through your XML before it has been loaded..

Edited by funkysoul, 27 April 2006 - 04:28 PM.


#7 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 27 April 2006 - 04:40 PM

But with this,

tempMc.empty_mc.holder_mc.loadMovie("data/thumbs/"+item_array[depth].childNodes[2].childNodes[0]);

the image did load... just the number isn't being recognized.. so the IF statement keeps failing..

What should I try to solve this problem now? can you take a look at my file?

#8 funkysoul

    The Funky Stuff

  • Publishing Betazoids
  • PipPipPipPip
  • 2,307 posts
  • Gender:Male
  • Location:Zurich, Switzerland
  • Interests:Music: HIM, HIM, HIM, Cafe del Mar, Linkin Park, Fort Minor, Coldplay, Eric Jordan<br />Sports: Snowboarding, KiteSurfing, Extreme Sports<br />Computer: Flash, After Effects, Actionscript

Posted 27 April 2006 - 05:08 PM

Just came up my mind:

what about creating a variable in the on enter frame function which holds the value of fwidth, something like this:

var myWidth:Number = bla bla bla your xml

and in your if statement instead of using this._fwidth just use myWidth..

#9 DarkSuiyoken

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 28 April 2006 - 06:08 AM

No luck with that too. :ph34r:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users