class - Initializing unknown type in Actionscript 3.0 -
to maintain programme running smoothly, have create objects when need them. in case, want see if object of unspecified class null, , if not, phone call tell initialize. (i think "initialize" right term, right me if wrong)
if (someobject == null) { someobject = new someobject.class() }
obviously, code not work. thought seems right, actionscript not agree me. how can achieved?
edit - perhaps help simplify (or complicate) answer. know someobject
extends class superclass
. can utilize property superclass
instantiate someobject
?
i'm going create effort @ getting on right track toward useful answer.
firstly, looking @ example:
if (someobject == null) { someobject = new someobject.class() }
i'm not sure you're trying convey here. if someobject
null
, cannot extract info it. if type someobject
e.g:
var someobject:sprite;
you cannot access info fact property someobject
expecting sprite
*
*you can utilize describetype()
access type if someobject
fellow member of class, lets not go there.
if want able to:
check if instance of specific class exists, , if not; create instance of specified class.you can write like:
var existing:object = { }; function findormake(type:class):* { var key:string = type.tostring(); if(!existing.hasownproperty(key)) { // need create new instance of class. existing[key] = new type(); } homecoming existing[key]; }
which can used like:
var someobject:sprite = findormake(sprite); // makes new sprite. someobject = findormake(sprite); // references above sprite.
actionscript-3 class flash initialization
No comments:
Post a Comment