0
Multiple instances of one object ?
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/td-p/967497
Mar 25, 2008
Mar 25, 2008
Copy link to clipboard
Copied
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
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
TOPICS
ActionScript
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Enthusiast
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967498#M26087
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967499#M26088
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
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.
> 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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Enthusiast
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967500#M26089
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
no I mean something like this
private var m_arr: Array = new Array(); ( m_ for member of class )
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 );
}
animMC is off-screen element ( if you find this way heplful I think I can write a function returns animMC )
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
private var m_arr: Array = new Array(); ( m_ for member of class )
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 );
}
animMC is off-screen element ( if you find this way heplful I think I can write a function returns animMC )
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967502#M26091
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
> 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()
> {
> 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()
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Enthusiast
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967504#M26093
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967505#M26094
Mar 27, 2008
Mar 27, 2008
Copy link to clipboard
Copied
> 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.
Ok. Lets analyse example below. loadFileClass will be a class loading, for
example, picture file with passed as argument name.
class myClass extends MovieClip
{
private var myState:Number;
public function setState(state:Number)
{
var externalFileObject;
myState=state;
externalFileObject=new loadFileClass("file"+myState.".jpg");
addChild(externalFileObject);
externalFileObject=new loadFileClass("file"+(myState+1).".jpg");
addChild(externalFileObject);
}
public function myClass()
{
}
}
var mcB, mcA=new myClass();
mc.setState(5);
mcB=clone(mcA);
I expect here to have mcB object having the same attached another object,
having the same myState value but with different instance name.
> 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.
Ok. Lets analyse example below. loadFileClass will be a class loading, for
example, picture file with passed as argument name.
class myClass extends MovieClip
{
private var myState:Number;
public function setState(state:Number)
{
var externalFileObject;
myState=state;
externalFileObject=new loadFileClass("file"+myState.".jpg");
addChild(externalFileObject);
externalFileObject=new loadFileClass("file"+(myState+1).".jpg");
addChild(externalFileObject);
}
public function myClass()
{
}
}
var mcB, mcA=new myClass();
mc.setState(5);
mcB=clone(mcA);
I expect here to have mcB object having the same attached another object,
having the same myState value but with different instance name.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967506#M26095
Mar 28, 2008
Mar 28, 2008
Copy link to clipboard
Copied
The OOP way of cloning is to have the Object clone itself.
Using your
example:
public interface ICloneable
{
function clone():Object;
}
class myClass extends MovieClip implements ICloneable
{
private var myState:Number;
public function setState(state:Number)
{
var externalFileObject;
myState=state;
externalFileObject=new loadFileClass("file"+myState.".jpg");
addChild(externalFileObject);
externalFileObject=new loadFileClass("file"+(myState+1).".jpg");
addChild(externalFileObject);
}
public function myClass()
{
}
public function clone():Object
{
var result:myClass = new myClass();
// set member values
// in this case, copying myState to the clone would
// not produce the desired effect, so we'll call the setState
// method.
result.setState(myState);
return myClass;
}
}
var mcB, mcA=new myClass();
mcA.setState(5);
mcB = myClass(mcA.clone());
//or
var mcB:MovieClip
var mcA:MovieClip = new myClass();
mcA.setState(5);
mcB = (mcA is IClonable) ? MovieClip(IClonable(mcA).clone()) : new
myClass();
Another look at cloning in AS3:
http://niko.informatif.org/blog/2007_07_20_clone_an_object_in_as3
example:
public interface ICloneable
{
function clone():Object;
}
class myClass extends MovieClip implements ICloneable
{
private var myState:Number;
public function setState(state:Number)
{
var externalFileObject;
myState=state;
externalFileObject=new loadFileClass("file"+myState.".jpg");
addChild(externalFileObject);
externalFileObject=new loadFileClass("file"+(myState+1).".jpg");
addChild(externalFileObject);
}
public function myClass()
{
}
public function clone():Object
{
var result:myClass = new myClass();
// set member values
// in this case, copying myState to the clone would
// not produce the desired effect, so we'll call the setState
// method.
result.setState(myState);
return myClass;
}
}
var mcB, mcA=new myClass();
mcA.setState(5);
mcB = myClass(mcA.clone());
//or
var mcB:MovieClip
var mcA:MovieClip = new myClass();
mcA.setState(5);
mcB = (mcA is IClonable) ? MovieClip(IClonable(mcA).clone()) : new
myClass();
Another look at cloning in AS3:
http://niko.informatif.org/blog/2007_07_20_clone_an_object_in_as3
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967508#M26097
Mar 28, 2008
Mar 28, 2008
Copy link to clipboard
Copied
Thanks Raymond for your help. This is what I looked for 🙂
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967501#M26090
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
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);
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);
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967503#M26092
Mar 26, 2008
Mar 26, 2008
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967507#M26096
Mar 28, 2008
Mar 28, 2008
Copy link to clipboard
Copied
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
Bob
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Newsgroup_User
AUTHOR
LEGEND
,
LATEST
/t5/animate-discussions/multiple-instances-of-one-object/m-p/967509#M26098
Mar 28, 2008
Mar 28, 2008
Copy link to clipboard
Copied
>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.
>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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

