Sunday, 11 September 2011

Technical Drawing Terms

[simpleaffiliate source="chitika" results="0"][/simpleaffiliate]
technical drawing terms
Draw a sprite in actionscript without using extends Sprite?

here's some code in as3:

package
{
import flash.display.Sprite;
import flash.text.TextField;
public class test extends Sprite
{
public function test()
{
var text:TextField = new TextField();
text.text = "Hello World!";
addChild(text);
}
}
}

Now you see the part "public class test extends Sprite"? How could I change this code so that it still displays hello world but without an extends Sprite (or extends anything for that matter)? In more technical terms I am asking how to implement this code as a composition rather than an inheritance.


You can create a sprite in your class and add the textfield to it, like below. However, if you want to see the result, you have to add the sprite to the display list. If you don't extend anything, you won't have addChild() to do so. But e.g. you can make your sprite variable public and add it to the display list from outside of the class.


package
{
import flash.display.Sprite;
import flash.text.TextField;
public class test
{
public function test()
{
var sprite:Sprite = new Sprite();
var text:TextField = new TextField();
text.text = "Hello World!";
sprite.addChild(text);
}
}
}


Essay 1 Assignment and Drafting









[simpleaffiliate source="amazon" results="6"]technical drawing terms[/simpleaffiliate]
[simpleaffiliate source="cj" results="2"]technical drawing terms[/simpleaffiliate]
[simpleaffiliate source="clickbank" results="5"]technical drawing terms[/simpleaffiliate]

No comments:

Post a Comment