Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with events and Movieclips

Guest
Sep 06, 2013 Sep 06, 2013

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.

TOPICS
ActionScript
4.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 08, 2013 Sep 08, 2013

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

...
Translate
Community Expert ,
Sep 06, 2013 Sep 06, 2013

what code executes when that button is clicked?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 06, 2013 Sep 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2013 Sep 07, 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..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2013 Sep 07, 2013

i'm not sure i understand you .

i understand the code you posted.  and i think i understand that you want to apply the code below Mouseevent to some other objects but those objects are png's, not movieclips.  is that correct?

if so, convert the png's to movieclips (right click the png on stage>click convert to symbol>movieclip>ok).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2013 Sep 07, 2013

I have movieclips of images sequences(pngs).

The code posted above is what I used for mouse event for the movieclip which is made visible by the button.

This code I have for every movieclip. That is as flash does not accept same variable, so changed the variable name and used the code for every mc.

Now  the main mc ie (the whole house). And other movieclips are parts of it as in garage etc. in png's.

As I told u, I have this situation where if I click on garage button, then only the mouse event for garage in functioning.

wen i want the main_mc the background also to move with the garage.

I hope I have presented clearly.

Thank u.

Any help please

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2013 Sep 07, 2013

if you want that code to apply to a group of two (or more) movieclips, reparent them and apply that code to the parent:

var p:MovieClip=new MovieClip();

addChild(p);

p.addChild(main_mc);

p.addChild(garage_horizon_mc);

var rotater_gah:MovieClip=p;

etc

////////////////////

or, if you want to apply that code to more than one movieclip concurrently, but not as a group, add that rotater_gah code to a function body and call that function sequentially.

whateverF(main_mc);

whateverF(garage_horizon_mc);

function whateverF(rotater_gah:MovieClip):void{

var offsetFrame_gah:int = rotater_gah.currentFrame;

etc

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2013 Sep 07, 2013

Thank u for the reply but it has not solved my problem.

The first solution was not triggering the function.

My movieclips are in timeline in separate layers.

The second one was calling the function, but the same problem.

Yes, I want to work these in groups only.

Please help..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2013 Sep 07, 2013

copy and paste the code you tried.  there's no need to try them both.  just use the one that does what you want.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 07, 2013 Sep 07, 2013

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);

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2013 Sep 08, 2013

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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 08, 2013 Sep 08, 2013

Thank u so much.

But there is an error, while compiling.

Scene 1, Layer 'actions', Frame 1, Line 1311120: Access of undefined property rotater_gah.

Line 131: e.currentTarget.offsetFrame_gah = rotater_gah.currentFrame;

What could I have done wrong??

Please help.

Thank u

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2013 Sep 08, 2013

my error.  that should be:

e.currrentTarget.offsetFrame_gah = e.currentTarget.currentFrame;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 08, 2013 Sep 08, 2013

Thank u again.

Sorry, but again I need help because the problem exists.

now whatever I am clicking it is functioning and rotating.

The  problem is,

For example; the garage_horizon_mc is a png sequence right?

now wen i am clicking the options (eg:garage_Horizon_mc), the background i.e. main_mc is hiding. actually i want the main also  to be rotating with the options i enable.

is it possible?

Hope i am clear.

Thank u so much once again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2013 Sep 08, 2013

again, if you want to group objects so the rotate etc together, reparent them to a common parent.

or, if you want to use the current approach but not have all the movieclips (like main_mc) be clickable, remove them from mcA.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 08, 2013 Sep 08, 2013

Sorry, I am so confused because its way beyond my knowledge.

Could u please explain.

Reparent them .....

var p:MovieClip=new MovieClip();

addChild(p);

p.addChild(main_mc);

p.addChild(garage_horizon_mc);

Is this what u were suggesting??

Please help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2013 Sep 08, 2013

yes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 08, 2013 Sep 08, 2013

Thank u.

But its not rotating now.

Any suggestions??

Please help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 08, 2013 Sep 08, 2013

again, show the complete code you're using and explain what's not rotating.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 09, 2013 Sep 09, 2013

Thank U so much.

I have added a target to rotate with same keyframe numbers.

It has successfully been solved.

Thank u again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2013 Sep 09, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines