[Flashcoders] Take movieclips from one mc and attach to another
Hello! I've found a nice code (pasted at the bottom of this mail) to display a rotating set of movieclips. One problem with it is though that it assumes a hardcoded set of 7 movieclips in the library, called 0, 1, ... 6 and attaches them to the stage by calling attachMovie(i, mc+i, i); I'd like to change that to a MovieClip-based class which would take an arbitary array of MovieClips and attach them to itself: class Ellipse extends MovieClip { private var mcs:Array = []; ... public function setMovieClips(mcs:Array) { this.mcs = mcs; for (var i:Number = 0; i mcs.length; i++) { var mc:MovieClip = mcs[i]; // XXX this.attachMovie(i, mc+i, i); And here comes the problem - how do I attach MovieClips (referred by mc above) to the Ellipse? There are only 2 methods - attachMovie() and duplicateMovieClip() - and they both need a linkage name as the argument. I.e. my general question is: how do I remove a child-MovieClip from one parent-MovieClip and assign it to another parent-MovieClip? Regards Alex PS: Here is the original code var N:Number = 7; var A:Number = 150; var B:Number = 50; var X:Number = 200; var Y:Number = 150; var GR:Number = Math.PI / 180; for (var i:Number = 0; i N; i++) { attachMovie(i, mc+i, i); this[mc+i].alpha = 0+i*(360/N); this[mc+i].onEnterFrame = function() { this.alpha += (_root._xmouse - X) / 100; this._x = X + A * Math.cos(this.alpha * GR); this._y = this._xscale = this._yscale = Y + B * Math.sin(this.alpha * GR); this.swapDepths(this._y); }; } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Take movieclips from one mc and attach to another
You can't re-parent MovieClips in AS2. You could make your class control arbitrary MovieClips as if they were reparented with a lot of math and localToGlobal() calls, though. Probably not a great idea, though. On 8/23/07, Alexander Farber [EMAIL PROTECTED] wrote: Hello! I've found a nice code (pasted at the bottom of this mail) to display a rotating set of movieclips. One problem with it is though that it assumes a hardcoded set of 7 movieclips in the library, called 0, 1, ... 6 and attaches them to the stage by calling attachMovie(i, mc+i, i); I'd like to change that to a MovieClip-based class which would take an arbitary array of MovieClips and attach them to itself: class Ellipse extends MovieClip { private var mcs:Array = []; ... public function setMovieClips(mcs:Array) { this.mcs = mcs; for (var i:Number = 0; i mcs.length; i++) { var mc:MovieClip = mcs[i]; // XXX this.attachMovie(i, mc+i, i); And here comes the problem - how do I attach MovieClips (referred by mc above) to the Ellipse? There are only 2 methods - attachMovie() and duplicateMovieClip() - and they both need a linkage name as the argument. I.e. my general question is: how do I remove a child-MovieClip from one parent-MovieClip and assign it to another parent-MovieClip? Regards Alex PS: Here is the original code var N:Number = 7; var A:Number = 150; var B:Number = 50; var X:Number = 200; var Y:Number = 150; var GR:Number = Math.PI / 180; for (var i:Number = 0; i N; i++) { attachMovie(i, mc+i, i); this[mc+i].alpha = 0+i*(360/N); this[mc+i].onEnterFrame = function() { this.alpha += (_root._xmouse - X) / 100; this._x = X + A * Math.cos(this.alpha * GR); this._y = this._xscale = this._yscale = Y + B * Math.sin(this.alpha * GR); this.swapDepths(this._y); }; } ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Take movieclips from one mc and attach to another
Thanks, but can't I this.duplicateMovieClip() the MovieClips passed to my class as arguments to its method and then removeMovieClip the original? Or createEmptyMovieClip() and the loadMovie() into it? Regards Alex On 8/23/07, Mark Hawley [EMAIL PROTECTED] wrote: You can't re-parent MovieClips in AS2. You could make your class control arbitrary MovieClips as if they were reparented with a lot of math and localToGlobal() calls, though. Probably not a great idea, though. On 8/23/07, Alexander Farber [EMAIL PROTECTED] wrote: MovieClip-based class which would take an arbitary array of MovieClips and attach them to itself: class Ellipse extends MovieClip { private var mcs:Array = []; ... public function setMovieClips(mcs:Array) { this.mcs = mcs; for (var i:Number = 0; i mcs.length; i++) { var mc:MovieClip = mcs[i]; // XXX this.attachMovie(i, mc+i, i); And here comes the problem - how do I attach MovieClips (referred by mc above) to the Ellipse? ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Take movieclips from one mc and attach to another
I don't think having the class extend MovieClip is the right way to do this. I'd just create a class and pass it an array of linkage names in which to attach. Try this: class Ellipse { function Ellipse(attachTo:MovieClip, linkageArray:Array) { var N:Number = linkageArray.length; var A:Number = 150; var B:Number = 50; var X:Number = 200; var Y:Number = 150; var GR:Number = Math.PI / 180; var ref:MovieClip; for (var i:Number = 0; i N; i++) { ref = attachTo.attachMovie(linkageArray[i], linkageArray[i], i); ref.alpha = 0+i*(360/N); ref.onEnterFrame = function() { this.alpha += (_root._xmouse - X) / 100; this._x = X + A * Math.cos(this.alpha * GR); this._y = this._xscale = this._yscale = Y + B * Math.sin(this.alpha * GR); this.swapDepths(this._y); }; } } } Then in Flash pass the constructor an attach to clip, and an array with linkage names. var e:Ellipse = new Ellipse(this, [sym_1,sym_2,sym_3,sym_4,sym_5,sym_6,sym_7]); PS - this way you can use a variable number of clips also - you don't need to use seven. HTH Dave - Head Developer http://www.blurredistinction.com Adobe Community Expert http://www.adobe.com/communities/experts/ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com