PDA

View Full Version : problem with creating text via classes inside packages.


ionic234
11-11-2007, 12:40 PM
Hi all

Im pretty new to actionscript 3 (more of a lingo programmer and i foolishly though the migration would be easy). Im trying to make a class which as part of its constructor calls a function to put some text on the stage. However while code compiles and all the trace statements are outputed showing that the code is exicuted but nothing appears on screen. Im guessing its to do with the addChild(txtSprite) on line 22 but have no idea what that should be.

The code start by creating a new instance of the quizControl class on frame 1 of the time line with the code :

import MathsQuiz.*;
var mainQuizControl:QuizControl = new QuizControl();
stop();

The code for the quizControl is in the package MathsQuiz (most of it is to do with text formating):

package MathsQuiz{

import flash.display.*;
import flash.text.*;


// A class that controls the swtiching of the lights.
public class QuizControl extends MovieClip {

// Vars
private var txtFormat:TextFormat;
private var txtSprite:Sprite;
private var txtField: TextField;

// Constructor
public function QuizControl():void {
trace("QuizControl Sucessfuly Constructed");

txtSprite = new Sprite();
addChild(txtSprite);
txtFormat = new TextFormat("Arial",24,0x330000,true,false,false,null,null,"center");
txtField = this.makeText("YO DUDES",txtFormat,txtSprite,0,60,550);

}
private function makeText(newText:String, tf:TextFormat, s:Sprite,x,y:Number, width:Number):TextField {

var tField:TextField = new TextField();
tField.x = x;
tField.y = y;
tField.width = width;
tField.defaultTextFormat = tf;
tField.selectable = false;
tField.multiline = true;
tField.wordWrap = true;

if (tf.align == "left") {
tField.autoSize = TextFieldAutoSize.LEFT;
} else {
tField.autoSize = TextFieldAutoSize.CENTER;
}
tField.text = newText;
s.addChild(tField);
trace ("MakeText finished");

return tField;
}
}
}

ive probably done something realy stupid or fundamentaly flawed but any help you can give me would be greatly appreciated. Thanks

Ionic234

jaga
11-11-2007, 07:06 PM
try

import MathsQuiz.*;
var mainQuizControl:QuizControl = new QuizControl();
addChild(mainQuizControl); // <----
stop();

ionic234
11-11-2007, 08:33 PM
Ahh cheers. Ill try that

thanks

Ionic234

WhoCares357
11-11-2007, 08:39 PM
Probly has nothing to do with the problem (may not even be a problem), but you mispelled null (nu ll) in TextFormat. Sorry I can't help you more than that. I'm still a big noob at scripting.