Populating the slideshow with a text file

using the string.split() function

Page 1 of 1

2 Replies - 4203 Views - Last Post: 13 June 2005 - 03:18 PM

#1 aircan7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 05

Populating the slideshow with a text file

Posted 13 June 2005 - 02:47 AM

Hello again.

I'm try to populate an array with an external text file for use in the slideshow code in my Previous post.

This is what I tried....

I have a text file named "image.txt" with a var called "images" in the text file.

In the _root timeline I have the following:

loadVariables("images.txt",_root);


In my slideshow movieClip I have the Slideshow code, but I changed it so the previous array, which was:

pics=["image1.jpg", "image2.jpg", "image3.jpg"]


is now this:

pics = _root.images.split(",");


but after doing this, the slideshow doesn't work and the "pics" variable comes up "undefined".

Can anyone tell me why? I thought that "whatever.split(","); would create an Array similar to the hand coded one above.

Is This A Good Question/Topic? 0
  • +

Replies To: Populating the slideshow with a text file

#2 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Populating the slideshow with a text file

Posted 13 June 2005 - 03:59 AM

I recommend you use XML. Much more stable.

However, if you want just .txt.. try this instead of your loadVariables:
var my_vars:LoadVars = new LoadVars();

my_vars.onload = function(success:Boolean) {
    if (success) {
        images = unescape(this).split(",");
        images.pop();        
    } else {
        trace("Error loading/parsing LoadVars.");
    }
};

my_vars.load("images.txt"); 


HOWEVER, teh images.txt files has to look like this:
image1.jpg,image2.jpg,image3.jpg,

..has to have the comma at the end.

With XML it would be very simmilar. Instead of loadVariables:
var xmlDoc:XML = new XML();
System.useCodepage = true;
xmlDoc.ignoreWhite = true;

xmlDoc.onload = function(ok:Boolean) {
    if (ok) {
        doMenu(this);        
    } else {
        trace("XML did not load");
    }
};

xmlDoc.load("images.xml");

function doMenu(xml:XML) {
    var num:Number = xml.firstChild.childNodes.length;    
    pics = new Array();    
    for (var i = 0; i < num; i++) {
        pics[i] = xml.firstChild.childNodes[i].attributes.image;        
    }
    trace(pics);    
} 

and your XML would look like this:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<MENU>
    <ITEM image="image1.jpg" />
    <ITEM image="image2.jpg" />
    <ITEM image="image3.jpg" />
    <ITEM image="image4.jpg" />
</MENU>


... of course,in the slideshow.swf you'd have to change this._parent.pics to _root.pics.
Was This Post Helpful? 0
  • +
  • -

#3 aircan7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-June 05

Re: Populating the slideshow with a text file

Posted 13 June 2005 - 03:18 PM

Does the xml code have to be on the _root timeline or can it go in the slideshow script itself?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1