-
Help! Need mouse click to play 2 different child movie clips at the same time
Hello and thanks for the help in advance!
I'm trying to get frame 2 of a movie clip (one_mc) on the main timeline to play, while at the same time it triggers frame 2 of the child movie clip (two_mc) to play. Movie clip two_mc is in the movie clip one_mc. My code is below, but I keep getting an null object error. I've tried a bunch of different combos, but nothing seems to work.
/*Play button plays frame 2 of one_mc, frame 2 of two_mc also plays*/
play_btn.addEventListener(MouseEvent.CLICK, play);
function play(e: MouseEvent): void {
one_mc.gotoAndPlay(2);
one_mc.two_mc.gotoAndPlay(2);
}
Is it impossible to get one mouse click to play frames in two separate movie clips?
Thanks!
-
.
Hi,
Your code will work, its just that two_mc does not exist in flashes eyes until it reaches frame 2 of one_mc, so therefore will throw an error when trying to call it before it exists, try putting the two_mc on frame one of one_mc and make it invisible, then make it visible on frame 2 of one_mc.
I think you can follow that
-
I follow, however I'm not sure where to put the code. Do I put it on the main timeline or frame 1 of one_mc? Right now on frame 1 of one_mc I have:
two_mc.visible = false;
On frame 2 i have:
two_mc.visible = true;
And it's not working. Thanks again.
-
.
Hi,
Perhaps you can do it like so,
PHP Code:
play_btn.addEventListener(MouseEvent.CLICK, plays); one_mc.two_mc.visible = false;
function plays(e:MouseEvent):void { one_mc.gotoAndPlay(2); addEventListener(Event.ENTER_FRAME, checks); }
function checks(e:Event):void { if (one_mc.currentFrame > 1) { one_mc.two_mc.visible = true; one_mc.two_mc.play(); removeEventListener(Event.ENTER_FRAME, checks); } }
no need for code in the movieclips, just the regular stop(); wherever you needthem.
the code goes on the main time line, two_mc is on frame one of one_mc.
I believe you will need to change the function play to something different (like above) as you will get an override error
-
It works! However, it breaks the other two functions I have attached to play_btn, which is to play a sound and show a selection around the clicked button (both on the main timeline).
-
.
Hi,
Well to help you any further we would need to see a working file as trying to guess what you have set up is pretty hard to achieve.
-
I really appreciate the help. I'm building a prototype/demo that is a little sensitive and don't feel comfortable posting it online.
-
.
Hi,
Well I can only suggest that you put your other function calls within the other one!!
Maybe make a small skeleton file of what it is you need, then perhaps things can be sorted for you.
good luck
-
This code is probably messy as I'm somewhat new to as3 and I'm not sure if seeing all of it helps at all. If needed I may be able to put together a dummy UI. This includes the code you suggested I use earlier...
play_btn.addEventListener(MouseEvent.CLICK, plays);
one_mc.two_mc.visible = false;
function plays(e:MouseEvent):void
{
one_mc.gotoAndPlay(2);
addEventListener(Event.ENTER_FRAME, checks);
}
function checks(e:Event):void
{
if (one_mc.currentFrame > 1)
{
one_mc.two_mc.visible = true;
one_mc.two_mc.play();
removeEventListener(Event.ENTER_FRAME, checks);
}
}
/*plays sound*/
play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var req:URLRequest = new URLRequest("sound.mp3");
mySound.load(req);
function onClickPlay(event:Event) {
myChannel = mySound.play();
}
/*button selection array*/
play_btn.addEventListener(MouseEvent.CLICK, onButtonSelect);
import flash.events.MouseEvent;
var group:Array = new Array(play_btn, stop_btn, fwd_btn, rev_btn, pause_btn);
var selectedButton:MovieClip;
function onButtonSelect( event:MouseEvent ):void
{
selectedButton = event.target as MovieClip;
for each(var btn:MovieClip in group){
btn.setSelected( btn == selectedButton );
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|