Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-11-2003, 05:15 PM   #1
montey
Senior Member
 
Join Date: Mar 2002
Location: New York
Posts: 521
Default Dynamically created buttons from txt file

Ok i'm loading a txt file with this info in it.
Code:
tammy=jes,dean,fran,oct,simmy,blanch,drean

&talk=bright,dark,canning,prut,stenk,blast

&drift=tt,ba,br
I am using the load vars()
Code:
function LoadArr(file) {
	arr_obj = new LoadVars();
	arr_obj.load(file);
	arr_obj.onLoad = function(success) {
		if (success) {
			buttons = new Array();
			buttons.push(arr_obj);
			trace(buttons);
		} else {
			trace("not loaded");
		}
	};
}
loadArr("arr.txt");
Now what I want to do is to dynamically create buttons from the variable names
tammy
talk
drift
then from the buttons I need to access the values of these variables.
[code]
tammy.onRelease=function(){
for (var i=0; i<tammy.length; i++) {
arr=tammy[i];

}
How in the hell can this be done.
montey is offline   Reply With Quote
Old 03-11-2003, 07:15 PM   #2
jaybee
Senior Citizen
 
jaybee's Avatar
 
Join Date: Feb 2003
Location: underneath the arches
Posts: 443
Default

if tammy talk and drift will always be the same you can do it like this, and you have a blank button mc in the library with a textfield nested within it:

ActionScript Code:
function loadArr(file) {     arr_obj = new LoadVars();     arr_obj.tl = this;     arr_obj.onLoad = function(success) {         if (success) {             var myArray = new Array("tammy", "talk", "drift");             var depth = 2;             for (var i = 0; i<myArray.length; i++) {                 var n = myArray[i];                 this.tl[n+"_arr"] = this[n].split(",");                 myInit._x *= i;                 var t = this.tl.attachMovie("button_mc", n+"_btn", depth++, {_x:150*i,_y:20});                 t.arrayName = t.name_txt.text=n;                 t.onRelease = function() {                     var arr = _root[this.arrayName+"_arr"];                     for (var i = 0; i<arr.length; i++) {                         trace(arr[i]);                     }                 };             }         } else {             trace("not loaded");         }     };     arr_obj.load(file); } loadArr("buttons.txt");

I tested this out in a fla and have attached it here - is this what you wanted?
Attached Files
File Type: zip buttons.zip (4.2 KB, 149 views)
jaybee is offline   Reply With Quote
Old 03-11-2003, 07:23 PM   #3
montey
Senior Member
 
Join Date: Mar 2002
Location: New York
Posts: 521
Default

The problem is I don't want to have to declare these variables in flash the should be in the txt file which they are with a value on them
Code:
var myArray = new Array("tammy", "talk", "drift");
These will change they may not be called these names and they might have different values.
I need to have them declared in the txt file like they are, then loaded into flash, then they are created into buttons and then these buttons can access there value.
Just like you have done except the var myArray = new Array("tammy", "talk", "drift");
has to be loaded in from a text file.
Thanks for your reply
montey is offline   Reply With Quote
Old 03-11-2003, 07:32 PM   #4
jaybee
Senior Citizen
 
jaybee's Avatar
 
Join Date: Feb 2003
Location: underneath the arches
Posts: 443
Default

ok then, replace the line

ActionScript Code:
var myArray = new Array("tammy", "talk", "drift");

ActionScript Code:
var myArray = new Array();             for(var i in this) {                 if (i != "tl" && i != "onLoad") myArray.push(i);             }

which works but the contents of thefor loop are an ugly hack - can't remember how this would be done with instanceof or typeof at the mo...it works tho.
jaybee is offline   Reply With Quote
Old 03-11-2003, 07:40 PM   #5
montey
Senior Member
 
Join Date: Mar 2002
Location: New York
Posts: 521
Default

This works. I am trying to go through it all and I may have a few questions later.
one is why this
arr_obj.tl = this;
the .tl
part....
Thanks so much for the reply and the amazing answer.
montey is offline   Reply With Quote
Old 03-12-2003, 08:53 AM   #6
jaybee
Senior Citizen
 
jaybee's Avatar
 
Join Date: Feb 2003
Location: underneath the arches
Posts: 443
Default

tl is a reference to the parent timeline that the loadvars object is on, cos the code in the loadhandler function is executed relative to the loadvars scope....so then you can say this.tl.someFunction() quite neatly.
jaybee is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:43 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.