Yeah, you're using the same MovieClip name reference. I do believe you can't have two objects share the same name. You'll get concurrency issues with that on this line:
_mcLibrary = _scope.attachMovie(libraryLink,"mcLibrary", _scope.getNextHighestDepth()); You'll need to create a unique ID for it. I would probably suggest either within your creation object, or have an ID factory (should probably be a hybrid Singleton/Factory) that just generates unique ID's that you can append to your instance names. As for the custom class, it's nothing more than a blank class with public variables (or private ones and getter/setter methods) that contain the data you want to pass. OR, since you use two separate objects, just have a single object compose both. There are many ways to go about doing it, so it just boils down to preference I guess. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bill Mackin Sent: Wednesday, May 23, 2007 1:42 AM To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] problem creating multiple instances This is how I am instantiating the creationObject (below). I believe that if I am passing a different name to the myName property it should create more than one MovieClip instance. I'd love to hear more about your suggestion to use a custom class to set properties instead of a generic object, or maybe point me in the direction of good tutorial or example. Unfortunately I am a self taught coder and am not always familiar with some of the best practices. var myCreationSettings:Object = { myName:"3DCircleOnCavill", libraryLink:"CircleOnCavill", scope:this, xAxisStart:-20, yAxisStart:20, vQuality:3, hQuality:3 } var my3Dplane:Simple3DPlane = new Simple3DPlane(myCreationSettings); my3Dplane.mouseReactive(true, 30, 20, true); var myCreationSettings2:Object = { myName:"3DCircleOnCavill2", libraryLink:"tom", scope:this, xAxisStart:-20, yAxisStart:20, vQuality:3, hQuality:3 } var my3Dplane2:Simple3DPlane = new Simple3DPlane(myCreationSettings2); my3Dplane2.mouseReactive(true, 30, 20, true); On May 23, 2007, at 3:20 PM, David Ngo wrote: > Looks like you're attaching your plane to the same MovieClip > instance, thus > destroying any/all objects that was previously on that MovieClip > instance. > Depends on how you're instantiating your creationObject. BTW, just > a comment > on your implementation: I would use a custom class to set > properties for > creation and animation rather than a generic object. This way, you > can avoid > having to iterate through the object and then you can just > composition your > custom class/object. In Java, this would be equivalent to a Value > Object or > a Data Transfer Object. > > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > Bill Mackin > Sent: Wednesday, May 23, 2007 12:51 AM > To: flashcoders@chattyfig.figleaf.com > Subject: Re: [Flashcoders] problem creating multiple instances > > Hello, > > Looks like the attachment did not go out. I've pasted the > Actionscript into this e-mail. > > Cheers, > > - Bill > > /* > Simple 3D Plane - v1.0 > ------------------------------------------------------------ > > Created : January 24, 2007 > Last Updated : May 18, 2007 > > Copyright © 2007 Pixlart. All rights reserved. > > http://www.pixlart.net > info [at] pixlart [dot] net > */ > > > /////////////////////////////////////////////////////////////// \\\\\\ > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > /* > DESCRIPTION Allows you to animate MovieClips and Bitmaps > on a 3D > plane with full control and easing. > > > AUTHOR(s) Bill Mackin - > http://www.billmackin.com > Combination > of scripts and development of 3D animation API. > > > Marquee Flipper - Which provided a good starting point and > combination of World3d and DistortImage. > ---- > Felix Turner - http://www.airtightinteractive.com > > Simple 3d Engine "World3d" - A very basic "light" 3D engine. > ---- > André Michelle - http://www.andre-michelle.com > > DistortImage - A class to distort an image (including > persective distortions) by slicing the image into smaller pieces > (generally triangles). > ---- > Thomas Pfeiffer "kiroukou" - http://www.thomas- > pfeiffer.info > ---- > Richard Lester "RichL" > ---- > Didier Brun "foxy" - http://www.foxaweb.com > > Easing Equations - Popular equations used by many to > provide easing effects in scripted animations. > ---- > Robert Penner - http://www.robertpenner.com > > ------------------------------------------------------------ > ------------------------------------------------------------ > USAGE > ------------------------------------------------------------ > ------------------------------------------------------------ > var myCreationSettings:Object = { > myName:"3DCircleOnCavill", > libraryLink:"CircleOnCavill", > scope:this, > xAxisStart:0, > yAxisStart:0, > mouseReactive:false, > vQuality:3, > hQuality:3 > } > var my3Dplane:Simple3DPlane = new Simple3DPlane(myCreationSettings); > > var myAnimationSettings:Object = { > xAxisTo:0, > yAxisTo:180, > animationDuration:1, > easingMath:"Expo", > easingType:"easeOut", > delay:1, > callBack:"doSomething", > callBackScope:this, > callBackArgs:[true, "both", 1] > } > my3Dplane.animate3DPlane(myAnimationSettings); > > my3Dplane.getTarget(); // returns an instance of the newly created > > MovieClip containing the 3D plane. > > my3Dplane.mouseReactive(true, 30, 20, true); @param1 = > turns 3D > movement based on mouse position on/off > > @param2 = the limit for the 3D movement on the x > axis, (in degrees). > > @param3 = the limit for the 3D movement on the y > axis, (in degrees). > > @param4 = determines whether the 3D plane rotates > towards the mouse or away, (only used when limiting angles). > ------------------------------------------------------------ > ------------------------------------------------------------ > NOTES > ------------------------------------------------------------ > ------------------------------------------------------------ > > BILL MACKIN > When using a MovieClip for your content, be sure to position > the > top left of your content at 0,0. > > TO DO > 1. Update so you can create several 3D plane instances and > control > each of them separately. > */ > /////////////////////////////////////////////////////////////// \\\\\\ > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > /////////////////////////////////////////////////////////////// > // INCLUDE / IMPORT ---> > // ------------------------------------------------------------ > import flash.display.BitmapData; > import flash.geom.Matrix; > import mx.utils.Delegate; > import ActionScript.simple3D.DistortImage > import ActionScript.simple3D.World3d > import ActionScript.Tools.PennerEasing > ////////////////////////////////////////////////////////////////////// > // > ////////////////////////////////////////////////////// > > > > > class ActionScript.simple3D.Simple3DPlane { > > // PROPERTIES // > ------------------------------------------------------------ > var myName:String; > // A name for the newly created 3D plane. > var libraryLink:String; > // A link to an item in the library > to be the content for the 3D plane. > var scope:MovieClip; > // The scope of the newly created 3D > plane. > var xAxisStart:Number = 0; > // The amount (in degrees) to rotate > the 3D plane pivoting on the x axis. (0 to -180 = backwards) & (0 to > 180 = forwards) > var yAxisStart:Number = 0; > // The amount (in degrees) to rotate > the 3D plane pivoting on the y axis. (0 to -180 = right) (0 to 180 = > left) > var vQuality:Number = 3; > // The vertical quality of the 3D > plane. Higher numbers equal better quality but slower performance. > var hQuality:Number = 3; > // The horizontal quality of the 3D > plane. Higher numbers equal better quality but slower performance. > > var xAxisTo:Number; > // The amount (in degrees) to rotate the > 3D plane on the x axis. > var yAxisTo:Number; > // The amount (in degrees) to rotate the > 3D plane on the y axis. > var animationDuration:Number; // > The duration (in seconds) of > the animation. > var easingMath:String; > // Possible values = "Back", "Bounce", > "Circ", "Cubic", "Elastic", "Expo", "Linear", "Quad", "Quart", > "Quint", "Sine" > var easingType:String; > // Possible values = "easeIn", > "easeOut", "easeInOut" > var delay:Number; > // Amount of delay (in seconds) before > starting the animation. > var callBack:String; > // Function to call when the animation > is finished. > var callBackScope:MovieClip; > // Scope for callBack. > var callBackArgs:Array; > // Array of arguments for callBack > (maximum of 8). > > // PRIVATE PROPERTIES // > ------------------------------------------------------------ > private var _mc:MovieClip; > private var _scope:MovieClip; > private var _bd:BitmapData; > private var _di:DistortImage; > private var _planeModel:Object; > private var _my3DWorld:World3d; > private var _mcLibrary:MovieClip; > private var _xa:Number = 0; > private var _ya:Number = 0; > private var _myMouseListener:Object = new Object(); > private var _noLimitAnimationInterval:Number; > private var _planeAnimationInterval:Number > private var _startTime:Number; > > > > function Simple3DPlane(creationSettings:Object) { > > // grab creation paramaters > for (var prop in creationSettings) { > this[prop] = creationSettings[prop]; > } > > // WARNINGS > if (!myName) trace("REQUIRED VALUE MISSING! The current > value for > myName = "+myName); > if (!libraryLink) trace("REQUIRED VALUE MISSING! The > current value > for libraryLink = "+libraryLink); > > > // INITIALIZE > _scope = (!scope) ? _level0 : scope; > var _zVertDist:Number; > var _zHorzDist:Number; > > // create BitmapData > if (BitmapData.loadBitmap(libraryLink)) { > _bd = BitmapData.loadBitmap(libraryLink); > } else { > _mcLibrary = > _scope.attachMovie(libraryLink,"mcLibrary", > _scope.getNextHighestDepth()); > _mcLibrary._visible = false; > _bd = new BitmapData(_mcLibrary._width, > _mcLibrary._height, true, > 0x000000); > var _mcMatrix:Matrix = new Matrix(); > _bd.draw(_mcLibrary, _mcMatrix, null, "normal", > null, true); > } > > // create mc to act as a container > _scope.createEmptyMovieClip (myName, > _scope.getNextHighestDepth()); > _mc = _scope[myName]; > > // create a DistortImage instance for the new mc > _di = new DistortImage(_mc, _bd, vQuality, hQuality); > _zVertDist = _mc._height/2; > _zHorzDist = _mc._width/2; > > // create 3D plane model > _planeModel = { points: [{x:-_zHorzDist, y:-_zVertDist, > z:0}, > {x:_zHorzDist, y:-_zVertDist, z:0}, {x:_zHorzDist, y:_zVertDist, z: > 0}, {x:-_zHorzDist, y:_zVertDist, z:0}], height:_mc._height}; > > // create 3D world renderer > _my3DWorld = new World3d(_planeModel); > > // render the 3D plane position > doRender(xAxisStart, yAxisStart); > }; > > > function animate3DPlane(animationSettings:Object) { > > var myThis:Simple3DPlane = this; //<--------------- IS THIS > > TROUBLE FOR CONTROLLING MULITPLE INSTANCES!!???? > > // grab animation paramaters > for (var prop in animationSettings) { > this[prop] = animationSettings[prop]; > } > > if (delay) { > var delayStart:Number = setInterval(start, > delay*1000); > } > else { > _startTime = getTimer(); > _planeAnimationInterval = setInterval(myThis, > "doAnimation", 34); > } > > function start() { > clearInterval(delayStart); > myThis._startTime = getTimer(); > myThis._planeAnimationInterval = setInterval(myThis, > > "doAnimation", 34); > } > }; > > > function mouseReactive(mrSwitch:Boolean, xAngleLimit:Number, > yAngleLimit:Number, attract:Boolean) { > > var myThis:Simple3DPlane = this; //<--------------- IS THIS > > TROUBLE FOR CONTROLLING MULITPLE INSTANCES!!????? > //trace("_my3DWorld="+myThis._my3DWorld.mModel.height); > if (mrSwitch) { > if (xAngleLimit || yAngleLimit) { > var neg:Number; > myThis._myMouseListener.onMouseMove = > function() { > neg = (attract) ? -1 : 1; > _xa = > neg*(myThis._mc._ymouse/(Stage.height/2)*xAngleLimit); > _ya = > neg*-(myThis._mc._xmouse/(Stage.width/2)*yAngleLimit); > myThis.doRender(_xa, _ya); > }; > Mouse.addListener(myThis._myMouseListener); > } else { > myThis._noLimitAnimationInterval = > setInterval(myThis, > "setNoLimit", 34); > } > } else { > clearInterval(myThis._noLimitAnimationInterval); > Mouse.removeListener(myThis._myMouseListener); > } > }; > > > function getTarget():MovieClip { > return _mc > }; > > > // ------------------------------------------------------------ > PRIVATE METHODS > ------------------------------------------------------------ > private function doRender(xAxis:Number, yAxis:Number) { > > // render 3D points > _my3DWorld.render(xAxis, yAxis); > > // set distortImage corners based on 3D plane positions > var pts:Object = _my3DWorld.points; > _di.setTransform(pts[0].sx, pts[0].sy, pts[1].sx, pts[1].sy, > pts > [2].sx, pts[2].sy, pts[3].sx, pts[3].sy); > }; > > > private function doAnimation() { > > var myThis:Simple3DPlane = this; > > var currentTime:Number = getTimer() - _startTime; > var easing:Function = PennerEasing[easingType+easingMath]; > var xAnimationIncrement:Number = easing(currentTime, > xAxisStart, > (xAxisTo - xAxisStart), animationDuration*1000); > var yAnimationIncrement:Number = easing(currentTime, > yAxisStart, > (yAxisTo - yAxisStart), animationDuration*1000); > doRender(xAnimationIncrement, yAnimationIncrement); > if (currentTime >= animationDuration*1000) { > doRender(xAxisTo, yAxisTo); > clearInterval(myThis._planeAnimationInterval); > doCallBack(); > } > }; > > > private function setNoLimit() { > _xa -= (_mc._ymouse*3) / 100; > _ya += (_mc._xmouse*3 ) / 100; > doRender(_xa, _ya); > }; > > > private function doCallBack() { > callBackScope[callBack](callBackArgs[0], callBackArgs[1], > callBackArgs[2], callBackArgs[3], callBackArgs[4], callBackArgs[5], > callBackArgs[6], callBackArgs[7]); > }; > } > > > > On May 23, 2007, at 2:05 PM, Bill Mackin wrote: > >> Hello, >> >> I'm having a problem with one of my class files. I've created a >> class to control the animation of a 3D plane, but I am unable to >> use multiple instances at the same time. I'm not sure what it is >> that is conflicting. Any ideas would be appreciated. >> >> I've attached the class file. If the other class files are needed, >> please let me know. I also have a test FLA that I have been using >> to test my progress on this problem. >> >> Cheers, >> >> - Bill >> _______________________________________________ >> 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 > > _______________________________________________ > 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 _______________________________________________ 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