PDA

View Full Version : confusion about instance names and variables in createTextField


petermoy
04-11-2003, 03:09 AM
I'm trying to develop a component that creates some dynamic text that displays the current value of a user-selected variable. The data will be sent via an XML socket.

One of the user component parameters is a string called rdout_var. Suppose the user enters the string "val1".

Within my component constructor, I try to create a text field:

_root.createTextField(this.rdout_var, 1, 10, 20, 40, 80);

My problem is that I can't seem to get access to the text field using the variable - I need to explicitly use the string name.

e.g. _root.val1.type = "dynamic";

Any suggestions on a flexible way to get around this problem? The component would be used multiple times on the stage so we can display the values of a number of different variables.

I'm pretty much a newbie when it comes to Flash and Actionscript so I'd appreciate any assistance.

Thanks.

CyanBlue
04-11-2003, 03:20 AM
Howdy...

Try this code...this.rdout_var = "val1";
_root.createTextField(this.rdout_var, 1, 10, 20, 400, 80);
this[this.rdout_var].border = true;
this[this.rdout_var].text = "Testing";
this[this.rdout_var].type = "Input";

petermoy
04-12-2003, 04:06 AM
Thanks, Jason. Your help is appreciated.

I tried out your suggestions today.

I was able to get the following working:

_root.createTextField(this.rdout_var, 1, 10, 20, 400, 80);
_root[this.rdout_var].border = true;


When I tried this, I had some problems:

this.createTextField(this.rdout_var, 1, 10, 20, 400, 80);
this[this.rdout_var].border = true;

It looked like I was setting the parameters OK in the debugger, but for some reason I wasn't seeing any of the text displayed. I'm a little puzzled by this.

The differences are that in the first case, the text field is on _level0.val1 while in the second case the text field is on _level0.rdout1.val1

Another problem that I ran into was that I needed to use different depths for each text field that I created in order to have more than one text field displayed at a time.

Anyway, I'm fighting my way through the Flash learning curve. Thanks again for your help.

Peter

CyanBlue
04-12-2003, 04:23 AM
Hm... I am sure I am not getting what you saying... :Dthis.rdout_var = "val1";
this.createTextField(this.rdout_var, 1, 10, 20, 400, 80);
this[this.rdout_var].border = true;
this[this.rdout_var].text = "Testing";
this[this.rdout_var].type = "Input";Is this code working for you???

If this code is not the case you want to talk about, can you explain it one more time in layman's term??? ;) Some sample might help me understand what you are trying to do...

petermoy
04-13-2003, 06:06 AM
I'm sorry that I was unclear.

The code that you have in your last reply does allow me to set the parameters of the text field without having to explicitly use the string name. I can use the debugger to see that the variables for the text fields created by my component are indeed getting set properly.

My problem, however, is that the text fields created in this manner are not being displayed on the stage. Is there something else that I need to do to get a nested movie clip to display?

I've attached an fla file containing the component I'm trying to get working.

Thanks for all your help.

Peter

CyanBlue
04-13-2003, 06:37 AM
Um... I haven't figured it out yet, but the code does create the text field at the bottom of the screen that says 'testing3'... The problem is that I do not see the first and second one... Hm...

CyanBlue
04-13-2003, 06:43 AM
Strange thing is that it seems like there are actually three text fields on the stage... Two invisible ones and one visible one... I am able to get the tab working fine and at every third tab, I get to see the tab on the last text field...

I really do not know... :( this.createTextField (this.rdout_var, _global.varnum, this._x, this._y, this._width, this._height);
this[this.rdout_var].tabIndex = _global.varnum;
this[this.rdout_var].type = "input";
this[this.rdout_var].variable = this.rdout_var;
this[this.rdout_var].border = true;
this[this.rdout_var]._visible = true;
this[this.rdout_var].backgroundColor = this.rdout_bgcolor;
tformat = new TextFormat(this.rdout_fontstyle, this.rdout_fontsize, this.rdout_fontcolor,
null, null, null, null, null, "right", null, null, null, null);
this[this.rdout_var].setnewTextFormat(tformat);
this[this.rdout_var].text = "testing " + _global.varnum + " : " + this._name;
trace("\tthis._name = " + this._name + "\t_global.varnum = " + _global.varnum + "\tthis._x = " + this._x + "\tthis._y = " + this._y);

petermoy
04-15-2003, 02:42 AM
Thanks Jason for taking a look at my problem. It has been a big help to me getting familiar with Flash and ActionScript by going through these forums. I appreciate your effort.

CyanBlue
04-15-2003, 07:13 AM
Um... Not much of help I was able to provide... :(

Did you solve the problem???

petermoy
04-16-2003, 05:23 AM
No, I never solved the problem. It was annoying since I spent a lot of time on it and I still don't know why it didn't work.

I did find a workaround that seems to work.
If I use

_root.createTextField(this.rdout_var, _global.varnum, this._x, this._y, this._width, this._height);
_root[this.rdout_var].border = true;

the text fields appear on the stage and I can update the variable values that get displayed.

CyanBlue
04-16-2003, 12:45 PM
Hm... Use of _root and this makes that difference??? :(

Well... I'm sorry that I can't help you much on this and good luck... Show us what you make when it is done... ;)

petermoy
04-19-2003, 04:07 AM
I figured out my problem. It turns out that the x and y parameters used in the createTextField are relative to the coordinate space of the movie clip it is contained in.

The text fields that I created were actually on the stage but outside the field of view. I needed to position the dynamically text field at (0,0) and fix the scaling so my fonts weren't too big.


this.createTextField (this.rdout_var, 1, 0, 0, this._width, this._height);
// change the readout movie scaling back to 100% after we've created the text field in
// the desired size
this._xscale = 100;
this._yscale = 100;

this[this.rdout_var].type = "dynamic";
...

CyanBlue
04-19-2003, 05:51 AM
Ouch... That was it??? :(

Well... Can't complain on the things that we cannot see... :(

Oh... I don't think you are embedding the font, and if you do scale the text without embedding the font will result in the same effect, which is no text... :D This doesn't really apply to your case, but since you brought it up... ;)