PDA

View Full Version : problem with setting text in an object



radioxromance
May 15th, 2004, 05:06 AM
I am working on a game, and have some characters set with lil boxes that should show their names and stats. I set the boxes like this, and this works fine:


character.prototype.statsBox = function(depth,x,y,name,HP,MP) {
this.depth = depth;
this.x = x;
this.y = y;
this.name = name;
this.HP = HP;
this.MP = MP;
this.statsClip = _root.attachMovie("stats_mc", "statsBoxMC", this.depth, {_x:this.x,_y:this.y});
};

I want to then set the stats for each character as it's box is placed. I added this to the end of the prototype.


this.nameBox_mc.playerName_txt.text = this.name;
It doesn't work. I could just go in and set the code for each character in a function after setting them, but it would be better if it were set when the boxes are set.
....
Okay I worked some more with it and still nothing. I think it's the way I'm thinking about it:
The movieclip is attached to enemy, so it should be enemy.statsClip, correct?
then the statsclip (comprised of clips named as so: stats_mc->nameBox_mc->playerName_txt [-> means nested in clip]).
So i should be able to call enemy.statsClip.nameBox_mc.playerName.txt.text correct? Also, these are named in the instance name area, and I can't member if I did this right, but I think I did.
And the clip (stats_mc) plays through about ten frames before it shows these mc's, does that change anything? It shouldn't cause the clip is placed and then stoped...
I know it's confusing, but thanks!

ehman
May 15th, 2004, 05:46 AM
I am still kinda confused as to whats doing on. But I think that you are having some problem becuase that you are setting the value of the textbox on a frame where its not on stage.

Try using the variable to refer to the textbox instead of the instance name.
intead of 'playerName_txt.text' assign a variable value to it from the properties panel and use the variable name instead of instancename.text to set the value of the text box

This is because while variables are carried across frames, instance name values are not.

radioxromance
May 15th, 2004, 05:53 AM
I'll try that, although not totally sure what you mean; I probably jsut need some sleep.
Another thing, if I'm udnerstanding correctly, is that it shouldn't matter the frame here cause it's stoped on the last frame... which is when the box is placed... so should it matter? I'll come back to this tomorrow and work on it. Thanks for the reply.

ehman
May 15th, 2004, 05:56 AM
it matters if you have

this.nameBox_mc.playerName_txt.text = this.name;

on the first frame but the playerName_txt is not on the stage till the last frame.

radioxromance
May 15th, 2004, 06:17 AM
Okay I fixed it... sort of. I did what you recomended, and I understand it now. I also decided that I had too many move clips nested so I jsut took the text box and put it directly in the stats_mc clip.
Problem now is that I have two characters on the screen and they both have the first name set. I am making these characters as objects, so shouldn't each of the clips have seperate variables; what I mean in, shouldn't there be a hero.statsClip.statsName_txt and a enemy.statsClip.statsName_txt, both being seperate since they are in different places? I am very confused as to why it would do this. this is my current code:


character.prototype.statsBox = function(depth,x,y,name,HP,MP) {
this.depth = depth;
this.x = x;
this.y = y;
this.name = name;
this.HP = HP;
this.MP = MP;
this.statsClip = _root.attachMovie("stats_mc", "statsBoxMC", this.depth, {_x:this.x,_y:this.y});
this.statsClip.playerName_txt = this.name;
};