View Full Version : Populate Array from External Source
xmental
01-11-2003, 07:08 PM
Can someone please point me in the right direction....
I'm trying to create an Array in Flash MX, from an external datasource....currently just trying to do it from a text file....
thxs.
x
CyanBlue
01-11-2003, 07:42 PM
Howdy... :)
Here is the simple way of doing it in FMX... If you are using F5, you will have to use loadVariables() function instead of LoadVars object...
dataLVs = new LoadVars();
dataLVs.load("data.txt");
dataLVs.onLoad = function(success)
{
if (success)
{
trace("Input data = " + this.data);
dataArray = this.data.split("|");
trace("Output Data = ");
for (i = 0 ; i < dataArray.length ; i++)
trace(" dataArray[" + i + "] = " + dataArray[i]);
}
}and this is the content of the text file, data.txt...data=100|200|300|400|500|600|700|800|90 0and here is the output of that...Input data = 100|200|300|400|500|600|700|800|900
Output Data =
dataArray[0] = 100
dataArray[1] = 200
dataArray[2] = 300
dataArray[3] = 400
dataArray[4] = 500
dataArray[5] = 600
dataArray[6] = 700
dataArray[7] = 800
dataArray[8] = 900See if this answers your question... Good luck... :)
xmental
01-11-2003, 09:27 PM
Thanks, that's perfect...it shows me all the little bits that I needed to know....
apprieciated...
x
xmental
01-11-2003, 10:51 PM
...I just have one other question...
if the text file was setup:
junkOne=A|B|C&
junklTwo=1|2|3&
junkThree=APPLES|ORANGES|PEARS&
Why does not adding in other 'split' lines like this:
ArrayOne = this.junkOne.split("|);
ArrayTwo = this.junkTwo.split("|);
ArrayThree = this.junkThree.split("|);
not populate the arrays?
know how to do that? split mutiple vars from external data source to multiple arrays?
freddycodes
01-12-2003, 12:42 AM
The problem lies in your text file. You have spaces between the & and the variables names. If you made it look like:
&junkOne=A|B|C&junkTwo=1|2|3&junkThree=APPLES|ORANGES|PEARS
It would work
CyanBlue
01-12-2003, 03:02 AM
I agree with freddycodes too...
This would be another ways of doing it...
&junkOne=A|B|C&
&junkTwo=1|2|3&
&junkThree=APPLES|ORANGES|PEARS&and watch out for the typos in your code... :p
freddycodes
01-12-2003, 04:56 AM
&junkOne=A|B|C&
&junkTwo=1|2|3&
&junkThree=APPLES|ORANGES|PEARS&
Except you have two at signs(is that what they are called) in between each variable. There should only be one.
&junkOne=A|B|C&
junkTwo=1|2|3&
junkThree=APPLES|ORANGES|PEARS
CyanBlue
01-12-2003, 05:29 AM
Oh... I guess those extra & signs bothered you, freddycodes...
The only reason why I used extra & signs is to pretty up the text file and make it easy to read since Flash doesn't get bothered with extra & signs... :)
freddycodes
01-12-2003, 05:46 AM
Well essentially what you are creating in the text file is a query string. Since && is rendundant I thought I would point it out. Just seems confusing to me thats all. You wouldn't have
http://www.somedomain.com?cat=1&&id=2&&page=3
So why do it in the text file, thats all.
CyanBlue
01-12-2003, 01:43 PM
Yup... Totally agreed... But like I said, the only reason why I have that is the cosmetic reason... Don't try to kill me with that... :)
Originally posted by xmental
[BWhy does not adding in other 'split' lines like this:
ArrayOne = this.junkOne.split("|);
ArrayTwo = this.junkTwo.split("|);
ArrayThree = this.junkThree.split("|);
not populate the arrays?
[/B]
it may be a typo in your post, but make sure you suround your pipe(|) with quotes when using split:
ArrayOne = this.junkOne.split("|");
xmental
01-13-2003, 04:13 PM
Okay, thanks all the split is working woderfully...just typos as assumed....
Here's a look at what I've done:
------------code---------------
//Setup a container to hold the variables loaded from external file
contain = new LoadVars();
contain.load("./scripts/final.txt");
//Split the arrays once the data is loaded
contain.onLoad = function(splitArrays) {
if (splitArrays) {
fPics = this.picture.split("89");
fTitle = this.title.split("|");
fContent = this.content.split("|");
fLink = this.Link.split("|");
//Calls function to build list after arrays are split
buildFeatlist();
}
};
//Build a list from the arrays
function buildFeatlist() {
spacing = 150;
var i = -1;
//Loops as many times as there are picture entries could be changed to a recordcount
while (++i<fPics.length) {
name = "fRow"+i;
y = i*spacing;
//flistHolder is empty MC on stage
flistHolder.attachMovie("fRow", name, i);
flistHolder[name]._y = y;
//Populate the Title dynamic text box
flistHolder[name].title.text = fTitle[i];
//Populate the content dynamic text box
flistHolder[name].content.text = fContent[i];
//Set variable to hold the path to were the pics are stored used in
//nested holder MC for AScript: picHolder.loadMovie(picPath);
flistHolder[name].picPath = fPics[i];
//Set variable to hold frame number (or could be modified to be URL)
//to set the actions for: on (release){ gotoAndStop(linkPath); }
flistHolder[name].linkPath = fLink[i];
}
}
stop();
--------end code-----------------
This seem to work fine. Anyone offer any comments?
My next task is somehow to get the final list to scroll....
I know how to do this with btns, and masks etc. but I would really like to use MX's scrollbar component or scrollpane component....anyone have suggestions?
x
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.