PDA

View Full Version : Trying to play a rotating movieclip in the timeline



limeman
July 13th, 2008, 02:20 PM
Hi,

I'm having a few difficulties trying to get my movieclip to play in the timeline when I press a button. For example, i've got 3 buttons: Home, Music production & mixes. When I click on any of the buttons I would like it to trigger the same movieclip. Here's the code:


//Nav buttons

home_Btn.addEventListener(MouseEvent.CLICK, goHome);
prod_Btn.addEventListener(MouseEvent.CLICK, goProd);
mix_Btn.addEventListener(MouseEvent.CLICK, goMix);

function goHome (e:MouseEvent):void
{
gotoAndStop("Home");
}
function goProd (e:MouseEvent):void
{
gotoAndStop("Production");
}
function goMix (e:MouseEvent):void
{
gotoAndStop("Mixes");
}

//rotating circle code 1

stage.addEventListener(Event.ENTER_FRAME, rotate);


function rotate(evt:Event):void
{

var dx:Number = stage.mouseX-myCircle.x;
var dy:Number = stage.mouseY-myCircle.y;
var angle:Number = Math.atan2(dy,dx);
myCircle.rotation = angle*180/Math.PI;
}

I think it's got something to do with the following line of code:


stage.addEventListener(Event.ENTER_FRAME, rotate);

Which just plays the mc when I publish the swf. If I could play it each time I click a button that would solve my issue, it's probably something simple, but i'm new to actionscript.

Appreciate any help

Many thanks,
LM

Chuckanucka
July 13th, 2008, 02:53 PM
you need to just put rotate() inside your button functions, unless i am missing something?

limeman
July 13th, 2008, 03:53 PM
Thanks for your response, I don't suppose you know how I would do that?

Sorry it's probably really basic but i'm still learning

Cheers,
LM

spectator
July 13th, 2008, 04:06 PM
//Nav buttons

home_Btn.addEventListener(MouseEvent.CLICK, goHome);
prod_Btn.addEventListener(MouseEvent.CLICK, goProd);
mix_Btn.addEventListener(MouseEvent.CLICK, goMix);

function goHome (e:MouseEvent):void
{
gotoAndStop("Home");
rotate();
}
function goProd (e:MouseEvent):void
{
gotoAndStop("Production");
rotate();
}
function goMix (e:MouseEvent):void
{
gotoAndStop("Mixes");
rotate();
}

//rotating circle code 1




function rotate():void
{

var dx:Number = stage.mouseX-myCircle.x;
var dy:Number = stage.mouseY-myCircle.y;
var angle:Number = Math.atan2(dy,dx);
myCircle.rotation = angle*180/Math.PI;
}

I think this should work.

limeman
July 14th, 2008, 03:29 PM
Hi Spectator,

Sorry for my late reply. I tried the code but unfortunetly it didn't work. I guess I'm going to have to try something different.

Thanks for your help,

LM