zionlocke
June 22 '04, 11:02 PM
If you've wanted to make any number of text fields in flash at a dynamic rate, you've come to the right place. My friend and I have been working on this problem today. We have discovered a grand solution to a difficult issue. Our goal was to create a tree diagram in flash to organize meetings for a student organization on our campus.
A TextField is normally created in flash with this:
//for handling a loop of a lot of objects
tempLooper = 1;
//string for the instance
testString = "instanceName" + tempLooper;
//levels for each field must be different make it increment for dynamic creation
level = 1;
//x position
x = 10;
//y position
y = 10;
//width
w = 300;
//height
h = 30;
//create the field from the variables above
_root.createTextField(testString, level, x, y, w, h);
Now that we have everything defined, let's come to the main point of this tutorial. I soon recognized that the textfields were stored in some kind of an array. I was searching for a good while until I ran across a tiny little piece of code. I could call the object by its name in a weird way. If you name all your textfield objects with "name" added to an integer, you may gain access to that textfield with the same string by doing the following.
Let's say we've run the code above. Now what we can do is this:
//for handling a loop of a lot of objects
tempLooper = 1;
//string for the instance
testString = "instanceName" + tempLooper;
//root is the array for any instanced object
_root[testString].text = "new string added";
You can also use this instead of root:
//this can be used instead of root for any movie that isn't root
//you may also be able to grab according to movie names
this[testString].text = "another replacement";
I hope this has been a useful tutorial, and I hope you enjoy flash's l33t way of handling instanced objects.
A TextField is normally created in flash with this:
//for handling a loop of a lot of objects
tempLooper = 1;
//string for the instance
testString = "instanceName" + tempLooper;
//levels for each field must be different make it increment for dynamic creation
level = 1;
//x position
x = 10;
//y position
y = 10;
//width
w = 300;
//height
h = 30;
//create the field from the variables above
_root.createTextField(testString, level, x, y, w, h);
Now that we have everything defined, let's come to the main point of this tutorial. I soon recognized that the textfields were stored in some kind of an array. I was searching for a good while until I ran across a tiny little piece of code. I could call the object by its name in a weird way. If you name all your textfield objects with "name" added to an integer, you may gain access to that textfield with the same string by doing the following.
Let's say we've run the code above. Now what we can do is this:
//for handling a loop of a lot of objects
tempLooper = 1;
//string for the instance
testString = "instanceName" + tempLooper;
//root is the array for any instanced object
_root[testString].text = "new string added";
You can also use this instead of root:
//this can be used instead of root for any movie that isn't root
//you may also be able to grab according to movie names
this[testString].text = "another replacement";
I hope this has been a useful tutorial, and I hope you enjoy flash's l33t way of handling instanced objects.