Skip to main content
September 7, 2013
Answered

Problem with events and Movieclips

  • September 7, 2013
  • 1 reply
  • 4522 views

Hi All.

I have myself in a situation where everything was perfect with mouse click and drag, keyboard events and zoom events.

The project is:

A movieclip with images sequence: For Original background.

And other movieclips: aslo images sequence (Pngs)

They were all given separate mouse events and zoom and key events.

Now wen I click the button with concerned movieclip to function, only the png image seuence is rotating and the main mc is not.

What should I do to rotate both the activated whichever png mcs and main mc also with these.

Please help.

Thank you in advance.

This topic has been closed for replies.
Correct answer kglad

garage_horizon_btn.addEventListener(MouseEvent.CLICK,garage)

function garage(event:MouseEvent):void

{

    images_mc.garage_horizon_mc.visible=true;

    images_mc.garage_horizon_mc.stop();

    images_mc.garage_moss_mc.visible=false;

    images_mc.garage_ocean_mc.visible=false;

}

garage_moss_btn.addEventListener(MouseEvent.CLICK,garage1)

function garage1(event:MouseEvent):void

{

    images_mc.garage_moss_mc.visible=true;

    images_mc.garage_moss_mc.stop();

    images_mc.garage_horizon_mc.visible=false;

    images_mc.garage_ocean_mc.visible=false;

}

images_mc.main_mc.stop();

rot(images_mc.main_mc);

rot(images_mc.garage_horizon_mc);

rot(images_mc.garage_moss_mc);

function rot(rotater:MovieClip):void

{

var offsetFrame:int = rotater.currentFrame;

var offsetX:Number = 0;

var percent:Number = 0;

rotater.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);

rotater.addEventListener(MouseEvent.MOUSE_UP,stopDragging);

function startDragging(e:MouseEvent):void

{

    rotater.addEventListener(MouseEvent.MOUSE_MOVE,drag);

    offsetX = e.target.mouseX;

}

function stopDragging(e:MouseEvent):void

{

    rotater.removeEventListener(MouseEvent.MOUSE_MOVE,drag);

    offsetFrame = rotater.currentFrame;

}

function drag(e:MouseEvent):void

{

    percent = (e.target.mouseX - offsetX)/rotater.width;

    var frame:int = Math.round(percent*rotater.totalFrames) + offsetFrame +1;

    while (frame>rotater.totalFrames)

    {

        frame -=  rotater.totalFrames;

    }

    while (frame<=0)

    {

        frame +=  rotater.totalFrames;

    }

    rotater.gotoAndStop(frame);

}

}


use:

var mcA:Array = [garage_horizon_mc,garage_moss_mc,garage_ocean_mc,gutter_ocean_mc,gutter_horizon_mc,gutter_moss_mc,main_mc];

for(var i:int=0;i<mcA.length;i++){

    mcA.addEventListener(MouseEvent.CLICK,garageF);

}

function garageF(e:MouseEvent):void{

    for(var i:int=0;i<mcA.length;i++){

        mcA.visible = false;

    }

    var mc:MovieClip = MovieClip(e.currentTarget);

    mc.gotoAndStop(rotationframe);

    mc.visible = true;

    whateverF(mc);

}

function whateverF(rotater_gah:MovieClip):void{

rotater_gah.offsetFrame_gah = rotater_gah.currentFrame;

rotater_gah.offsetX_gah = 0;

rotater_gah.percent_gah = 0;

rotater_gah.addEventListener(MouseEvent.MOUSE_DOWN,startDragging_gah);

rotater_gah.addEventListener(MouseEvent.MOUSE_UP,stopDragging_gah);

}

function startDragging_gah(e:MouseEvent):void {

    e.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE,drag_gah);

    e.currentTarget.offsetX_gah = e.target.mouseX;

}

function stopDragging_gah(e:MouseEvent):void {

    e.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE,drag_gah);

    e.currentTarget.offsetFrame_gah = rotater_gah.currentFrame;

}

function drag_gah(e:MouseEvent):void {

    e.currentTarget.percent_gah = (e.target.mouseX - e.currentTarget.offsetX_gah)/e.currentTarget.width;

    var frame_gah:int = Math.round(e.currentTarget.percent_gah*e.currentTarget.totalFrames) + e.currentTarget.offsetFrame_gah +1;

    while (frame_gah>e.currentTarget.totalFrames) {

        frame_gah -=  e.currentTarget.totalFrames;

    }

    while (frame_gah<=0) {

        frame_gah +=  e.currentTarget.totalFrames;

    }

    e.currentTarget.gotoAndStop(frame_gah);

}

1 reply

kglad
Community Expert
Community Expert
September 7, 2013

what code executes when that button is clicked?

September 7, 2013

Hi,

I have this for every button and a mouse event and key event and zoom event added.

Below is the button function:

garage_horizon_btn.addEventListener(MouseEvent.CLICK,garage)

function garage(event:MouseEvent):void

{

garage_horizon_mc.gotoAndStop(rotationframe);

garage_horizon_mc.visible=true;

garage_horizon_mc.stop();

garage_moss_mc.visible=false;

garage_ocean_mc.visible=false;

gutter_ocean_mc.visible=false;

gutter_horizon_mc.visible=false;

gutter_moss_mc.visible=false;

main_mc.visible=false;

}

Mouseevent:


var rotater_gah:MovieClip = garage_horizon_mc;
var offsetFrame_gah:int = rotater_gah.currentFrame;
var offsetX_gah:Number = 0;
var percent_gah:Number = 0;

rotater_gah.addEventListener(MouseEvent.MOUSE_DOWN,startDragging_gah);
rotater_gah.addEventListener(MouseEvent.MOUSE_UP,stopDragging_gah);

function startDragging_gah(e:MouseEvent):void
{
rotater_gah.addEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
offsetX_gah = e.target.mouseX;
}

function stopDragging_gah(e:MouseEvent):void
{
rotater_gah.removeEventListener(MouseEvent.MOUSE_MOVE,drag_gah);
offsetFrame_gah = rotater_gah.currentFrame;
}

function drag_gah(e:MouseEvent):void
{
percent_gah = (e.target.mouseX - offsetX_gah)/rotater_gah.width;

var frame_gah:int = Math.round(percent_gah*rotater_gah.totalFrames) + offsetFrame_gah +1;

while (frame_gah>rotater_gah.totalFrames)
{
  frame_gah -=  rotater_gah.totalFrames;
}
while (frame_gah<=0)
{
  frame_gah +=  rotater_gah.totalFrames;
}
rotater_gah.gotoAndStop(frame_gah);
rotationframe  =  garage_horizon_mc.currentFrame;
}

I want this mouse event for every movieclip so added separately for all mcs. the problem is this being a png could be able to trigger the main_mc being static wen clicked this button.

What to do??

Or otherwise can I add the mouse event and keyboard event to the stage itself making it common for all movieclips which are image seuences???

Please help..

Thank you in advance.

September 7, 2013

I have different vaiables assigned to eah mc's mouse event. So can I use The these multiple mouse events simultaneously atleast.

Is there any possiblity of that sort??

Please help..