Skip to main content
Inspiring
March 25, 2008
Question

Multiple instances of one object ?

  • March 25, 2008
  • 6 replies
  • 1573 views
Hi,

Does anybody know how to create many instances of loaded object? I need to
add preloaded image from external source (Loader class) to many MCs (using
addChild()). When I call method addChild() do second object, image
dissapears from first object because its name of instance is exactly always
the same. In order to avoid this problem I decided to clone this image each
time I adding it to MC. Unfortunately I don't know how to create another
instance of image without repeating loading it again from the network.

Thanks for the help,
Marek


This topic has been closed for replies.

6 replies

Inspiring
March 29, 2008
>I came across Object.constructor in the docs today -- I don't know if you
>could use it usefully for a DisplayObject that came from a loader.

Hi Bob,

Raymond's answer solved my problem and it works fine. It seems that each
object type must be cloned in separate way.


Known Participant
March 28, 2008
I came across Object.constructor in the docs today -- I don't know if you could use it usefully for a DisplayObject that came from a loader.

Bob
Inspiring
March 26, 2008

U¿ytkownik "Raymond Basque" <nospam-rbasque-at-jednm-dot-com@nospam.com>
napisa³ w wiadomo¶ci news:fsdik3$ht8$1@forums.macromedia.com...
> Maybe something like this:
>
> function getLoaderImageCopy(loader:Loader):Bitmap
> {
> var o:DisplayObject = loader.content;
> // see BitmapData ctor for additional args
> var img:BitmapData = new BitmapData(o.width, o.height);
> img.draw(o);
> var bmp:Bitmap = new Bitmap(img);
> return bmp;
> }
> var newImg:Bitmap = getLoaderImageCopy(myLoader);
> this.addChild(newImg);

Thanks Raymond. It works fine and solves my problem :-)
By the way - is any way to clone not bitmap movie clips? Sometimes MC has
complex structure and contains attached a couple of another MC's including
bitmaps and other objects.



Inspiring
March 26, 2008
Maybe something like this:

function getLoaderImageCopy(loader:Loader):Bitmap
{
var o:DisplayObject = loader.content;
// see BitmapData ctor for additional args
var img:BitmapData = new BitmapData(o.width, o.height);
img.draw(o);
var bmp:Bitmap = new Bitmap(img);
return bmp;
}
var newImg:Bitmap = getLoaderImageCopy(myLoader);
this.addChild(newImg);





Inspiring
March 26, 2008
Hi Kalisto,

> Hi,
> you can store instanced clip in array. Than you can do what you want with
> instances.
> I look into your site and see wath the problem is. The way to solve it
> dependent of implementation of animation.

Did you mean:

arr=new Array();
arr.push(myMc);
arr.push(myMc);
arr.push(myMc);
...

I think that it will not working because
arr[0].name==arr[1].name==arr[2].name...
All cells of array will refer to the same MC with the same instance name.


Inspiring
March 26, 2008
> private function attachClip( animMC: MovieClip )
> {
> var mc:MovieClip = MovieClip( this.addChild( animMC ) ); // You may
> not
> cast if you no need of MovieClip than use displayObject as type for mc;
> m_arr.push( mc );
> }
>
> Of course this is an example for my previous post. I don't know how you
> make
> animations and for this reason i may confuse you instead helping you

The MovieClip class constructor has no parameters so I can't use it as a
method of clonning MCs.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html#MovieClip()


Inspiring
March 27, 2008
HI, please tell me you what you mean under "clone"? In AS3 every item in library is associated with class ( can be custom class or can be created automatically by flash ). You may have many INSTANCES of this class in stage with different names.
Inspiring
March 26, 2008
Hi,
you can store instanced clip in array. Than you can do what you want with instances.
I look into your site and see wath the problem is. The way to solve it dependent of implementation of animation.
If I must do this effect I will make a dummy MovieClip ( to store the chossen bitmat ) and make a MovieClip( for example: animClip ) with this effect. When a bitmap is choosen i will create a instance of animClip and store its reference into array( if I need to hold this reference for some reason ). Then I will place a bitmap in dummy clip. Into last frame of animation I will call a function ( or rise an event ) to now which animation is ended.
I think you do someting like this.