-
1. Re: Placing objects with the mouse in Flash CS4
Rob Dillon Oct 4, 2009 8:44 AM (in response to Me2LoveIt2)You need to create a new instance of the Library object and then you need to position the new instance and then you need to add the instance to the display object, in this case the stage. It might go something like this:
function addApple(event:MouseEvent):void{
var libObject:ObjectName = new ObjectName();
libObject.x = mouseX;
libObject.y = mouseY;
addChild(libObject);
};Function needs to start with a lower case "f". The variable name that you create can be anything. The ObjectName will be the Class name that you gave to your object in the Library.
-
2. Re: Placing objects with the mouse in Flash CS4
Me2LoveIt2 Oct 5, 2009 9:26 AM (in response to Rob Dillon)Thank you for the reply.
I still do not fully understand though, because I tried your suggestions but get errors.
I tried this code:
stage.addEventListener(MouseEvent.MOUSE_DOWN, addApple); function addApple(event:MouseEvent):void{ var libObject:Apple_mc = new Apple_mc(); // <-- This line gives me two errors libObject.x = mouseX; libObject.y = mouseY; addChild(libObject); };This is basically what you send me, but I am getting two errors in line 4:
1046: Type was not found or was not a compile-time constant: Apple_mc
1180: Call to a possibly undefined method Apple_mc
"Apple_mc" is the drawn picture of an apple inside a movie clip.
What do you thing the problem with this code or setup might me?
~Thanks for your help and advice~
-
3. Re: Placing objects with the mouse in Flash CS4
Rob Dillon Oct 5, 2009 5:50 PM (in response to Me2LoveIt2)The object that you want to duplicate must be a movieClip or Button object that is in the movie's Library and has the "Export for Actionscript" option set. When you set this option, Flash will create a Class name for this object. This is the name that you need to use in the code.
var libObject:Apple_mc = new Apple_mc()libObject is the name of the variable that will contain the new object instance, you can use any name that you like for this part. Apple_mc should be the name of the Class from the original object that is in the Library.
-
4. Re: Placing objects with the mouse in Flash CS4
Me2LoveIt2 Oct 6, 2009 8:34 AM (in response to Rob Dillon)Thank you this is what I needed.
I did not know about the Export for Actionscript option, that was what held me back.
Thanks it works now!


