PDA

View Full Version : Textfield problem.



tic
November 27th, 2008, 07:33 PM
Hi,
wth this tut. http://www.emanueleferonato.com/2008/11/11/as3-flash-game-creation-tutorial-part-4-score/

Ive used to code to add a score.. but i got the error "1119: Access of possibly undefined property Scoretext through a reference with static type Score."

Now ive looked at the library of his fla (the rar is on the buttom of the tut page)
And there is a score on the library..

Now is it possible to get the same effect withouth having anything (like a textfield) on the library?

So, can you make the textfield by just using as3..

scottc
November 27th, 2008, 07:52 PM
get the line: http://www.kirupa.com/forum/showthread.php?t=313070

and the error means, Score doesn't have a property called Scoretext aka "Score.Scoretext" is undefined.

My guess is that.. you will need to define it on the class or instance of the object/class, or change the scope to public, so it can be accessed.

also might help to post the relevant lines of code. :P

edit:

So, can you make the textfield by just using as3..
yup...


var tf:TextField = new TextField();
tf.text = "hi";
addChild(tf);
Don't forget to import the TextField class. :)

tic
November 27th, 2008, 08:03 PM
package {

import flash.display.Sprite;

// look! you need text.TextField in order to make it work

import flash.text.TextField;

public class Score extends Sprite {

public function Score() {

// this.scoretext.text = "0" works

// this.scoretext.text = 0; does not work

this.Scoretext.text=String(0);

}

public function Updatescore(Score) {

// updating the score

this.Scoretext.text=String(Score);

}

}

}(I already had the lines)

The lines that give the error are 18 and 26 aka the this.Scoretext.text=String(0); and this.Scoretext.text=String(Score);

Do I need to post the codes in the Main class and the target class that refer to this code to?


Edit: I've got it to work.. thnx