flash - How to use a new movieClip as a Class or to copy it without reference to its class? -


i doing looping background 2 identical bg movieclip (b1 , b2). 2 "new" same class.

var b1:movieclip = new bg(); var b2:movieclip = new bg(); 

but because bg class picture loader internet , picture rather big. when addressed loading using progressevent. picture loaded 2 times. there anyway create b2 based on b1 without using new bg() again? since makes new bg loader code inside. thank ^^

for bg class code:

var urlvar:urlrequest; var bgloader : loader = new loader( ); urlvar = new urlrequest( "somewherelink.jpg" ); bgloader.load(urlvar); this.addchild(bgloader); 

is there way set if b1 loaded, copy b2? or other way achieve same goal?

import flash.display.*; import flash.utils.*; var obj:class = getdefinitionbyname(“bluebox”) class; addchild(movieclip(new obj())); 

i found 1 in dynamically create class, dunno how use t_t, can explain me , can use in situation? thank time ^^

for answer i'm going assume going want have same image twice, rather 2 different ones. problem have bg class load , attach internally. preferred approach load once, , create instances of loaded content.

//first lets create single loader var bgloader:loader = new loader(); bgloader.contentloaderinfo.addeventlistener(event.complete,completehandler); //and load content var urlvar:urlrequest = new urlrequest("somewherelink.jpg"); bgloader.load(urlvar); //notice don't add loader stage  function completehandler(evt:event):void {     //remove loader listener memory conservation purposes     evt.target.removeeventlistener(event.complete,completehandler);     //reference content     var content:displayobject = evt.target.content;     //so create bitmapdata object     var bmd:bitmapdata = new bitmapdata(content.width,content.height,false); // use (content.width,content.height,true,0) if loading image transparancy     //and draw loaded image bitmap data     bmd.draw(content);     //now can create many bitmap objects data     var bg1:bitmap = new bitmap(bmd);     var bg2:bitmap = new bitmap(bmd);     //offset bg2 both visible     bg2.x = 100;     addchild(bg1);     addchild(bg2); } 

for second question... getdefinitionbyname returns object represents named class, rather instance of it. in example, getting definition class 'bluebox', in root of application source (not in folder).

once have class object can create instances of new keyword. big disadvantage of far i'm concerned don't import class, hence in example obj cast movieclip. makes features of code editors code completion , error highlighting not work correctly because properties , methods of 'bluebox' not exposed.

i use creating objects have classes defined elsewhere, in xml file loaded @ runtime example.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -