Reputation: 2628
What is the difference between:
[Embed(source = "../assets/graphic.png")]
const GRAPHIC:Class;
var graphic:Bitmap = new GRAPHIC();
addChild(graphic);
And:
[Embed(source = "../assets/graphic.png")]
const GRAPHIC:Class;
addChild(new GRAPHIC());
And which one of these should I use and why?
Upvotes: 0
Views: 359
Reputation: 2558
The first is a variable pointer to the instantiated copy of the GRAPHIC
class. The second is an implicit declaration.
You would use the pointer if you needed to perform further operations on the object. For example...
graphic.name = "myGraphic";
graphic.alpha = 0.5;
someFunction(graphic);
Setting properties, and passing it as an argument to other functions are good cases for a pointer. If you don't need to do this, you can use the implicit declaration. You can do this in other places when it makes sense. For example...
var settings:Object = {
"x":20,
"alpha":0.5
}
setProperties(foo, settings);
// Instead, you can do it in one line, with an implicit declaration.
setProperties(foo, {"x":20, "alpha":0.5});
Upvotes: 2