Copy link to clipboard
Copied
I have a text file with variables and an swf that a friend made for me. Unfortunately i dont have the .fla file and i am trying to recreate it.
the file contains 3 variables with values, repeated 4 times and a final variable (called varDone) that tells it there are no more variables.
The three variables are varImage, varURL, varText. These are used to load images that can be clicked to open a website and they have a textfield above them.
The flash is a banner that we use on our site to display these images. Somehow, he reads the first set of variables into a movieclip i believe, where the image then fades in and stays on screen for 3 more seconds and then goes onto the next image. He keeps reading variables from the file until he hits that varDone=1 variable, then the banner starts all over. The file is such that I can add as many sets of variables as i want, and it will display all of them, it could be 3 or 10 or 30, as long as i add a new set of (varImage, varURL, varText) to the file ahead of the varDone variable. I thought maybe he might be loading those 3 variables into a two dimensional array and then processing them that way. This is the part I don't know how to do, how to read each set of variables, until i get to the varDone=1. I can do all the other stuff, I just don't know how to read this file.
It looks like the following:
&varImage=http://www.mofc-gaming.com/themes/CT_RN_GREYSCALE/images/spotlight1.jpg
&varHeadline=RECRUITING BAD COMPANY 2 MEMBERS
&varLink=http://badcompany2.ea.com/#/home
&varImage=http://www.mofc-gaming.com/themes/CT_RN_GREYSCALE/images/spotlight2.jpg
&varHeadline=Join MOFC in EVE Online
&varLink=http://www.eveonline.com
&varDone=1
XML is what you want. You would get a 1D array (not 2D - no need for 2D at all). An xml file like this would suffice:
<Pics>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
</Pics>
Then in Flash, you load the xml file and the resulting XML object you get can be parsed liek this:
_xm
...
Copy link to clipboard
Copied
Well, AS3 doesn't have LoadVars - so there are a couple of ways you could go. Personally, I'd redo the text file as XML - as3 has awesome XML parsing. In lieu of that though, you could use the URLLoader class... load the file, and you could use String.split to split the text with the ampersand into an array... but I think that's probably more trouble than it's worth. I think your best bet is to go with XML.
Copy link to clipboard
Copied
Using XML, would the variables be then loaded into an array, that way it doesn't matter how many sets are in the file, it just loads them all in to a 2D array so they can be parsed? I may have tried to overexplain the program in the first place. Basically, we have what looks like a banner on our site. This banner fades in for 2 seconds, holds for 2 seconds then the image changes (the next one fading in). I managed to recreate this same effect by creating a new banner with all the images inside the flash file already, and adding/removing code based on number of images i currently use. I just want to be able to do it the way our original banner did, and load images dynamically into a clip, do the whole fade in/show for 2seconds/make it clickable/ move on to the next one. I want to be able to have I guess an XML file, that I can edit, add or remove image info, and have it work. You can see the banner at http://www.mofc-gaming.com this is the new one i had done where everything is inclusive to the swf file and no external data file.
Copy link to clipboard
Copied
XML is what you want. You would get a 1D array (not 2D - no need for 2D at all). An xml file like this would suffice:
<Pics>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
<image url="www.image1.jpg"> Text to display along with Image could go here.</image>
</Pics>
Then in Flash, you load the xml file and the resulting XML object you get can be parsed liek this:
_xmlObject.image; <-returns an XMLList of all 'image' nodes in the xml document.
_xmlObject.image[0]; <-returns the first XML Object found in the XMLList described above. When treated as a String it will output "Text to display along with Image could go here."
_xmlObject.image.@url[0] <- returns the string "www.image1.jpg"
This will teach you everything you need to know: http://www.kirupa.com/developer/flashcs3/using_xml_as3_pg1.htm
Hope this helps. For AS3 nothing beats XML for loading dynamic data.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more