Copy link to clipboard
Copied
i have a txt_blk1 up to txt_blk32 and i also have a txt_we .. if the text_we.text has a value of 1 to 32 how can i change the value of txt_block0-32.text to 0.. the text we already generates its own value so i dont have to use for loop. i've tried to use _root["txt_blk"+txt_we.text] = 0; im using actionscript 2 .. can someone help me
Copy link to clipboard
Copied
If txt_blk#'s are also textfields, then you need to assign the 0 to the text property...
_root["txt_blk"+txt_we.text].text = 0;
If they are variables then that line should work.
If it still fails, try tracing the number of characters in the text_we textfield. If it happens to have more than you expect, it might be defined as a multiline textfield where it needs to be a single line
If that code is on the root timeline I recommend using "this" instead of "_root". Unnecessary use of _root is best avoided.
Copy link to clipboard
Copied
the textfield wont still change to zero.. but thank you sir it means a lot.. the txt_blk1-32 change its value when a hittest run on a mc_chip ive made. i have 24 chips and if the chip somehow collide with the block then it will change depending on what chip is moved but doesnt change the value to 0 when it leaves a block .. im making a board game similar to checkers. just sharing what i'm going through right now.. again sir thank you
Copy link to clipboard
Copied
You should show the code that is related to the problem you are haviing. It does not appear trhe one line of code is where the problem lies. I see you started another posting, so if you are pursuing this further in that posting I will stop trying to help here.
Copy link to clipboard
Copied
i'm sorry sir.. its just that im on a hurry and i need all the help that i can get for my thesis.. so while i havent figure out what to do for this problem.. i have to move to another problem just to save time. and another thing is i don't really know where did i go wrong..
this is the code i've put inside the chips
on (press) {
blocknum=32;
for(i=1;i<=blocknum;i++){
_
if (this.hitTest(_root["block"+i])) {
this._x=_root["block"+i]._x;
this._y=_root["block"+i]._y;
trace("Source "+i)
_root.txt_recent.text = i;
break;
}
/*if (this._x==_root["block"+i]._x and this._y==_root["block"+i]._y) {
_root.txt_recent.text = i;
trace("block "+i);
break;
}*/
}
startDrag(this);
//tempx=this._x;
//tempy=this._y;
}
on (release) {
blocknum=32;
for(i=1;i<=blocknum;i++){
if (this.hitTest(_root["block"+i])) {
trace("des1:"+parseInt(_root.txt_recent.text)+3 );
trace("des2:"+parseInt(_root.txt_recent.text)+4 );
trace("des3:"+parseInt(_root.txt_recent.text)+5 );
trace("des4:"+parseInt(_root.txt_recent.text)-3 );
trace("des5:"+parseInt(_root.txt_recent.text)-4 );
trace("des6:"+parseInt(_root.txt_recent.text)-5 );
if(i==parseInt(_root.txt_recent.text)+3 or i==parseInt(_root.txt_recent.text)+4 or
i==parseInt(_root.txt_recent.text)+5 or i==parseInt(_root.txt_recent.text)-3 or
i==parseInt(_root.txt_recent.text)-4 or i==parseInt(_root.txt_recent.text)-5) {
this._x=_root["block"+i]._x;
this._y=_root["block"+i]._y;
_root.txt_we.text = _root.txt_recent.text;
_root["txt_blk"+txt_we.text].text = 0;
_root.txt_recent.text = i;
break;
}
else{
this._x=_root["block"+_root.txt_recent.text]._x;
this._y=_root["block"+_root.txt_recent.text]._y;
break;
}
and this is the code i putted on the block13
all block have corresponding txt_blk according to its number:
onClipEvent(enterFrame) {
chipnum=24;
for(i=1;i<=chipnum;i++){
if (this.hitTest((_root["chip"+i]))) {
_root.txt_blk13.text = i;
}
}
}
Copy link to clipboard
Copied
The first thing you should do is trace the string you are creating to make sure it is creating what you think it should be...
trace("txt_blk"+txt_we.text);
If you need to use _root to target the other objects, then you probably need to use it to target txt_we as well.
Copy link to clipboard
Copied
so if i trace and it inputted a NaN then there's something wrong in my code ?
Copy link to clipboard
Copied
Yes, I would have to conclude that somewhere there is a problem with your code if you are not seeing the data you expect to see in the trace.
If you are saying that the txt_we.text portion is tracing "NaN" in that trace, then I have to conclude that the txt_we textfield is displaying "NaN" as well since there is nothing in the trace that is trying to coerce the text property to be a number.
Focus on running down what defines the text_we text. USe the trace function to hunt down where the problem originates
Find more inspiration, events, and resources on the new Adobe Community
Explore Now