how to change font and size of a TextField
Change it inside a TextFormat object and give it to the TextField object
I mean,once you have your TextFiel
Code:
vat te:TextField = new TextField();
create your TextFormat
Code:
var fo:TextFormat = new TextFormat();
fo.font = "Arial";
fo.size = 15;
and put it in the defaultTextFormat property of your TextField
Code:
te.defaultTextFormat = fo;
te.text = "blablabla";
addChild(te);
You can change other things like color, bold, italic
italic and bold are just boolean stuff, give it a true if you want to use it
Code:
fo.bold = true;
fo.italic = true;
fo.color = 0xFF0000;
There are other things you can do with TextFormat, like create links, but they are not much game related, i think
changing properties without care about the scope
In AS2 to change something in a MovieClip that is inside other clip you have to type his whole scope like
Code:
_root.MasterClip.blasterClip._x = 10;
In AS3, however,you can change it no matter where he is in the display list
Code:
var sp1:Sprite = new Sprite();
addChild(sp1);
var sp2:Sprite = new Sprite();
addChild(sp2);
var mc:MovieClip = new MovieClip();
mc.x = 10;
sp1.addChild(mc);
trace(mc.x);//10
sp1.removeChild(mc);
sp2.addChild(mc);
trace(mc.x);//10
classes with acess to the '_root'
how to make your classes have acess to the former '_root'
Two ways to do this:
First one,( wich i will not use anymore)is pass a reference to
the stage when you create it or later
like
var something:so = new so(this);
or
something.stageReference = this;
When you declare something in the stage
Inside your class you have some object that will store that reference
I will not use this anymore, this was a dirty cheap quick fix that messes
with the constructor function and mess with everything and i dont like it
Now, another way is to use the Event
ADDED
This event is dispatched when a displayObjects adds something to his displayList
So, inside the stage you can put a function like this
Code:
stage.addEventListener("added", addedHandler);
function addedHandler(ev){
ev.target.onAddedToStage();
}
ev.target is the object added.
And what it will do is to call a function onAddedToStage on a child
whenever any child is added
From the moment it is addChilded, your child class knows who is his .parent ,
Inside your child you will have to have this function,in wich you
do anything you want to do with your stage reference
Code:
function onAddedToStage(){
stageReference = this.parent;
//and you do what you want with it
stageReference.addEventListener("enterFrame", onEnterFrame);
}
There are other ways to do this, there is also an event onAddedToStage
wich not work in the f9 alpha, senocular also made a class to let your
childs know when they are added to anything...many ways
more about stageReference
This killing the edit button sux
Anyway, IF your child will be removed from stage this
stageReference = this.parent;
will not work so its better to use something like
Code:
//(inside the class)
//(inside the constructor function)
hasStageReference = true;
//outside constructor function, this is the function that receives the //reference to the stage
function setStageReference(obj){
stageReference = obj;
//do stage stuff
stageReference.addEventListener("enterFrame", oef);
}
//on the stage
stage.addEventListener("added", addedHandler);
function addedHandler(ev){
if(ev.target.hasStageReference){
ev.target.setStageReference(this);
}
}
I also dont like this way so much, maybe the best would be to use the correct onAddedToStage event, but i would rather wait for the new flash to use it
bytesLoaded and bytesTotal
there is also the event progress, wich broadcast an event with the propertys bytesLoaded and bytesTotal, wich can be good to make a preloader
Code:
var re:URLRequest = new URLRequest("loaded_.swf");
var ld:Loader = new Loader();
ld.contentLoaderInfo.addEventListener("complete", ch);
ld.contentLoaderInfo.addEventListener("progress", pgHandler);
ld.load(re);
addChild(ld);
ld.y = 200;
function pgHandler(ev){
trace(" bytesLoaded: " + ev.bytesLoaded + " bytesTotal: " + ev.bytesTotal);
}
function ch(ev){
trace("complete!!");
}