Copy link to clipboard
Copied
Hi guys,
I have a movie clip that I am dynamically loading into my scene when a button is pressed. I then want to add a mouse event listener to the Movie Clip object so it can trigger a function when clicked. I get an error when trying to do this and cannot find a solution anywhere.
Here is my code:
newLayerBT.addEventListener(MouseEvent.CLICK, newLayerBT_CLICK);
function newLayerBT_CLICK(MouseEvent):void{
layerCount = layerCount + 1;
//Make a new object from my BlankLayerMC class
var newLayer:BlankLayerMC = new BlankLayerMC;
addChild(newLayer);
//position the new object
newLayer.y = prevY + newLayer.height;
//Edit text inside object to reflect current layerCount
newLayer.layerName.text = "Layer " + layerCount;
newLayer.layerNum = layerCount;
prevY = newLayer.y;
//My problem occurs with this line....
newLayer.addEventListener(MouseEvent.CLICK, moveSelection);
layerArray.push(newLayer);
}
function moveSelection(e:MouseEvent):void{
var t = e.target;
layerSelectedGraphic.x = t.x;
layerSelectedGraphic.y = t.y;
}
Any help would be greatly appreciated
change:
function newLayerBT_CLICK(MouseEvent):void{
to:
function newLayerBT_CLICK(e:MouseEvent):void{
Copy link to clipboard
Copied
copy and paste your error message.
Copy link to clipboard
Copied
ReferenceError: Error #1069: Property CLICK not found on flash.events.MouseEvent and there is no default value.
at FlashCCSim_fla::timelineToolbar_6/newLayerBT_CLICK()
Copy link to clipboard
Copied
change:
function newLayerBT_CLICK(MouseEvent):void{
to:
function newLayerBT_CLICK(e:MouseEvent):void{
Copy link to clipboard
Copied
Wow, yea that fixed it.... didn't think I had to include that unless I was going to access the target being passed. Thank you very much.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now