all groups > flash actionscript > january 2004 >
You're in the

flash actionscript

group:

Assigning instance name to variable



Assigning instance name to variable bhenry17
1/18/2004 6:57:21 PM
flash actionscript: Hi all,

I have a movie with 65 buttons. When you click on a button, it calls data from an external .txt file.
My question is, how can I assign the instance name of each button to a variable so that I can use the exact same code for each button rather than changing the name for each entry.

If the client wants to add buttons, I don't want to have to go into each button and type the "data entry" number for each one. I have been at this for a few days and am not thinking clearly anymore :)

on (release){
loadVariablesNum("data.txt",0);

_root.onData = function(){
_root.DataBox.info.htmlText=lot01; <====I want this to be a the instance name so I don't have to retype it for each button


Thanks in advance, I am sure it is a simple matter of syntax, I am just too fried to figure it out....



bhenry

Re: Assigning instance name to variable Jack.
1/18/2004 9:26:13 PM
if i'm thinking along the right lines :)

you add a button with instance name lot66,
it loads data.txt, which contains -
&lot65=blah&
&lot66=text for lot66&

add a function to the main timeline, that responds to the
instance name of the button as the received parameter,
and use it to show the value returned in a textfield.

function loader(lot){
lv = new loadVars();
lv.load("data.txt");
lv.onLoad = function(){
_root.DataBox.info.htmlText = lv[lot];
};
};

lot66.onPress = function(){ pass = this._name; loader(pass); };

hth ?

regards
Re: Assigning instance name to variable bhenry17
1/20/2004 2:49:28 AM

Hi Jack.

Thanks for your response. It does however, leave me in the same position of having to edit each button script.

lot60.onPress = function(){ pass = this._name; loader(pass); };
lot61.onPress = function(){ pass = this._name; loader(pass); };
lot62.onPress = function(){ pass = this._name; loader(pass); };

This is the code I have currently (button script):

on (release){
loadVariablesNum("data.txt",0);
//Create text formats
myFormat = new TextFormat();
//create the rules for the text formats
myFormat.size=12;
myFormat.font="arial";

//Text box
_root.DataBox.createTextField("info",1,10,65,220,200);

//Properties for the text box
_root.DataBox.info.html=true;
_root.DataBox.info.multiline=true;
_root.DataBox.info.wordWrap=true;


//Function to wait for the data to load
_root.onData = function(){
_root.DataBox.info.htmlText=lot01; <=====This is the line I have to replace for every button
_root.DataBox.info.setTextFormat(myFormat);

}
}

So I am trying to figure out a way to have it recognize itself (like this._name) but that is not working. Maybe Flash can't do that. I am fairly new with ActionScript to know all the rules hehe.

I will keep plugging away at it. But thanks for your help. Much appreciated.

--bhenry


Re: Assigning instance name to variable Jack.
1/20/2004 4:37:09 PM
the only workaround i can find, is to put the button in a movieclip, and give the clip an instance name which you then pass to the button event,

on(release){
lot = _name;
trace("lot? - "+lot);
lv = new loadVars();
lv.load("data.txt");
lv.onLoad = function(){
_root.createTextField("field",10,20,100,100,30);
_root.field.text = lv[lot];
};
}

regards
AddThis Social Bookmark Button