Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple loadvariables actionscript 2

Status
Not open for further replies.

SCelia

Programmer
Feb 27, 2002
82
CA
my simple script:

loadVariablesNum("url-is-here", 0);

//create arrays
cName = clName.split(",");
cColor = clColor.split(",");
xCoord = xlCoord.split(",");
yCoord = ylCoord.split(",");

Ok if I test this movie the arrays cName, cColor etc are undefined. A trace on clName etc turns up undefined. However, if I use the debug menu in test movie to list the variables I see the variables "Variable _level0.clName" etc and they have the correct content so It must load them correctly. Why then do the trace and split functions return undefined?

A star to whoever solves this one

Thanks, Celia
 
Your problem is that the conversions are trying to take place before the TXT file has loaded. Try this ... make an empty movieClip and call it "converter". Place it on stage and put these actions on it:
Code:
onClipEvent (load) {
 loadVariables("file.txt", this);
}
onClipEvent (data) {
 with (_root) {
  cName = this.clName.split(",");
  cColor = this.clColor.split(",");
  xCoord = this.xlCoord.split(",");
  yCoord = this.ylCoord.split(",");
 }
}
This movieClip will load the TXT file, then when the data transfer has completed it will set each of the arrays in the main timeline.
 
LOL, that makes sense, I guess action script is not like other scripting languages in that way. Thanks a million. Celia
 
Hmm

Symbol=loadvars, Layer=Layer 1, Frame=1: Line 1: Clip events are permitted only for movie clip instances
onClipEvent (load) {

Symbol=loadvars, Layer=Layer 1, Frame=1: Line 4: Clip events are permitted only for movie clip instances
onClipEvent (data) {

I created a new symbol of type "movie clip" but it doesn't seem to think it's a movie clip. How do I create a movie clip?

Thanks, Celia
 
Check if it's behavior (right-click it in the Library) is really a movie clip, and if not change it and drag a new instance of it on stage.
If you're using Flash 5, you should right-click it once it on stage, select actions, and set that actionscript in the window that'll come up! Regards,

new.gif
 
I did that and it's a movie clip alright. Using Flash MX. Celia
 
Usually this warning comes up if you've put the actions into a frame. ClipEvents need to be directly atached to the movieclip itself - select the clip on the stage and then enter the code into the action panel directly, don't actually select a frame.
 
Ok, now my problem is doing something with the vars. They are in a new level, ie. _root.loadvar but I figured out how to send them to _root. Trouble is nothing is displaying. Here I'll show you my code.

Loadvar movie clip:

onClipEvent (load) {
loadVariables(" this);
}
onClipEvent (data) {
//create arrays
_root.cName = clName.split(",");
_root.cColor = clColor.split(",");
_root.xCoord = xlCoord.split(",");
_root.yCoord = ylCoord.split(",");

}

Actions layer of the main movie:

var i = 0;
myColor = new Color("cId"+i);
myColor.setRGB("0x"+ cColor);
with (this["cId"+i]) {
_x = xCoord;
_y = yCoord;
}

Thanks, Celia
 
Code:
onClipEvent (load) {
loadVariables("[URL unfurl="true"]http://localhost/StarWars/get_clusters.php";,[/URL] this);
//  I think the above line should be 
//  loadVariables("[URL unfurl="true"]http://localhost/StarWars/get_clusters.php",[/URL] this);
}
onClipEvent (data) {
//create arrays
_root.cName = clName.split(",");
_root.cColor = clColor.split(",");
_root.xCoord = xlCoord.split(",");
_root.yCoord = ylCoord.split(",");

}

Actions layer of the main movie:

var i = 0;
myColor = new Color("cId"+i);
myColor.setRGB("0x"+ cColor);
with (this["cId"+i]) {
    _x = xCoord;
    _y = yCoord;
}
Anyways, the original code I gave you sets the arrays up in the main timeline (hence "with (_root) {" ... I didn't just put that in for jollies!).
 
with (_root) { } doesn't set the vars up in the main timeline for some reason...

Variable _level0.loadvar.cName = [object #2, class 'Array'] [

placing the _root. in front of the var name does the trick tho.

I have a dynamic text field labelled cID0 and with cName[0] as the content var. Unfortuantly the contents of cName[0] do not display, and if the color and position change I wouldn't notice it for that reason. How can I get it to display? Celia
 
I don't think you can access the array directly like that ... your textfield needs to display a variable name, not an array address. Try this instead: make the textfield display cNameContents, and each time the contents of the textfield have to change, just change the variable "cNameContents" to the new array address. For example:

cNameContents = cName[0]

will intially set the contents to slot 0 in the array. If you want to view the next slot, just change the variable:

cNameContents = cName[1]

That way you have a textfield which can display multiple content sets, instead of having dedicated textfields for a single set of contents. Knowledge is attained only by seeking out that which is unknown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top