How can I click anywhere on stage to attach a movieclip to the x and y coords of the mouse, Thanks
Printable View
How can I click anywhere on stage to attach a movieclip to the x and y coords of the mouse, Thanks
Hi,
This should get you started, with a new *.fla, create a moveiclip and give linkage name of newClip, do not put it on the stage.
and in the same fla use this codePHP Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
var addedClip:MovieClip;
stage.addEventListener(MouseEvent.MOUSE_DOWN, addClip,false,0,true);
function addClip(e:MouseEvent):void
{
trace("Clicked");
addedClip = new newClip();
addedClip.x = stage.mouseX;
addedClip.y = stage.mouseY;
addChild(addedClip);
}
Hi,
I think you said something about removing it too, so.
ideally, you would put the new clips inside another clip on the stage rather than adding them to the stage directly.PHP Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
var addedClip:MovieClip;
var containerClip:MovieClip = new MovieClip();
stage.addEventListener(MouseEvent.CLICK, addClip,false,0,true);
addChild(containerClip);
function addClip(e:MouseEvent):void
{
trace("Stage clicked");
addedClip = new newClip();
containerClip.addChild(addedClip);
with (addedClip)
{
x = stage.mouseX;
y = stage.mouseY;
addEventListener(MouseEvent.MOUSE_DOWN,removeMe,false,0,true);
}
}
function removeMe(e:MouseEvent):void
{
trace("Removed me");
e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN,removeMe);
e.currentTarget.parent.removeChild(e.currentTarget);
}
Thanks, Check your paypal :) can you comment the code though, trying to actually learn as3 since I guess im moving up here and abandoning as2
And if you get truly stuck, here is the fla, CS5
Thanks for the donation Alloy, I shall spend it wisely.
can do later alloy if somebody else doesn't, about to eat now...
Its cool, ill figure it out
How can I change that removeme listener to be a hitest, im trying to get gravity to work on the movieclips so they fall down as you click, and they will hit some other movieclip under em to delete them
Hi,
Quickly though Alloy as the girlfriend wants to watch movie together, something like soPHP Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
var addedClip:MovieClip;
var containerClip:MovieClip = new MovieClip();
stage.addEventListener(MouseEvent.CLICK, addClip,false,0,true);
addChild(containerClip);
function addClip(e:MouseEvent):void
{
trace("Stage clicked - clip added");
addedClip = new newClip();
containerClip.addChild(addedClip);
with (addedClip)
{
x = stage.mouseX;
y = stage.mouseY;
addEventListener(Event.ENTER_FRAME,removeMe,false,0,true);
}
}
function removeMe(e:Event):void
{
e.currentTarget.y += 5;
if (e.currentTarget.hitTestObject(someOtherMovieClip))
{
e.currentTarget.removeEventListener(Event.ENTER_FRAME,removeMe);
e.currentTarget.parent.removeChild(e.currentTarget);
trace("Removed me");
}
}
thx
TypeError: Error #1034: Type Coercion failed: cannot convert someOtherMovieClip$ to flash.display.DisplayObject.
at gravitydrops_fla::MainTimeline/removeMe()
wont remove
Hi,
The error code is telling you that it is coming from the removeMe() function, obviously it wont remove it.
you can either look up the error codes and work it out for yourself or attach your *.fla file, even a skeleton version if needed, as it works with my test example.
Try to fix it, I will fund you some more
Hi,
You need to do either one of two things here.
Firstly give the bluebox a name and remove the linkage name from the library of the bluebox.
or
manually remove the bluebox from the stage and attach it using code usuing the linkage name, same way as addedClip is done.
I think most people would say try not to put things directly on the stage.
Thanks, Check your paypal
Also if you need any art work for your projects I got you, I make really good 8bit