Results 1 to 6 of 6
-
May 30th, 2011, 10:36 AM #120Registered User
posts
MC with button to other page, doesn't work
Hi,
I have a mc (houses_mc on frame1) (a long image the user can pan to the left or right) and I want to place some buttons in this movieclip to go to another page when CLICK. I put the second page on the second frame in the timeline, and so on. ( Is this alright or should I open it in a scene or as a new fla file?)
So far I can't get my button work. It seems that As3 doesn't like btns placed in mc or something like that. The roll over and hover and hit works all fine, but when I click it doesn't go anywhere.
The code I put for the button in the actions layer is:
this.underground_btn.addEventListener(MouseEvent.C LICK, goUnderground);
root.function goUnderground(e:MouseEvent):void //or without root.
{
gotoAndStop("2");
}
It seems that I need something different here. I also tried to get the button as a mc and tell it to work like a button, but again I just got errors.
Would be great if someone could help.
-
May 31st, 2011, 01:46 AM #2
gotoAndStop(2); without the quotes
-
May 31st, 2011, 03:21 PM #320Registered User
postsOh thanks, haven't seen this, but this isn't sloving the problem. Sure not sure how to get my buttons to work inside a movieclip.
-
May 31st, 2011, 04:15 PM #4
Is that extra space in CLICK actually in your code? Could that be the culprit?
MouseEvent.C LICK, goUnderground
-
May 31st, 2011, 05:00 PM #599Programmer
postsA few assumptions on how you have things set up...
I assume all of this code is on the main timeline.
Then on the stage in frame 1, you have houses_mc.
Inside houses_mc you have other MovieClips (I'll assume underground_mc) you want to turn into buttons.
When you use "this" in your code, you are refering to the main timeline, not child objects... so if you want to add an event listener to your underground_mc you will need to "dig" into the houses_mc object. aka
You will also probably want to do a few "basic" things usually done for turning MovieClips into buttons...Code:this.houses_mc.underground_mc.addEventListener(MouseEvent.CLICK, goUnderground); // NOTE: You do not need "this." at the beginning
You also may run into a further issue so at the beginning of your code, you may want to put...Code:houses_mc.underground_mc.buttonMode = true; // This makes the mouse cursor turn into the pointer finger on MouseEvent.MOUSE_OVER houses_mc.underground_mc.mouseEnabled = true; // This should default to true, but always good to make sure
This code allows children of this object to recieve their own events independent of the parent. (aka, if this is false, because "underground_mc" is technically "part" of "houses_mc", when you mouse over "underground_mc", you will not get a seperate event from "houses_mc".Code:houses_mc.mouseChildren = true;
Last edited by Josh Martin; May 31st, 2011 at 05:02 PM. Reason: Readability
-
May 31st, 2011, 06:05 PM #620Registered User
posts@skarab: no that's not the thing, it just looks like that here in the forum.
@josh martin: thanks a lot for your suggestions. Yes, its all in the action layer on the main timeline. It works with mc insted of button symbol. Thanks so much. It is so easy and I have worked all way around...ahhh. but thanks
Now just when I click the button, I get an error in the output:
at WeWatch_MJ_fla::MainTimeline/loop()
TypeError: Error #1009
so far I can't see what it is disturbing then as it works, but doesn't look right either.... any suggestions?
When you Click now the underground_mc (button) you go to frame 2 (label: underground). This underground (frame2) isn't a movie clip, just a background image, or a new page. I worte the action stop(); in frame 2, so that it doesn't go back to frame 1.
I hope this helps someone to understand my issue in order to help me. I really stuck.Code:var centreX:Number; var steps:Number; var scale:Number; stop(); init(); function init():void { centreX = stage.stageWidth/2; steps = 50; scale = steps/stage.stageWidth/2; addEventListener(Event.ENTER_FRAME,loop); // addEventListener for Button houses_mc.mouseChildren = true; houses_mc.underground_mc.addEventListener(MouseEvent.CLICK, goUnderground); houses_mc.underground_mc.buttonMode = true; houses_mc.underground_mc.mouseEnabled = true; } function loop(e:Event):void { if ( Math.abs(centreX -stage.mouseX) > 100) { var displaceX:Number = (Math.round(scale *( centreX -stage.mouseX))); displaceX=displaceX *1; // other panning elements houses_mc.x=houses_mc.x+displaceX; bags_mc.x =bags_mc.x+ (displaceX*1.02); postbox_mc.x =postbox_mc.x+ (displaceX*1.2); publicLitter_mc.x =publicLitter_mc.x+(displaceX*1.2); fourBoxes_mc.x =fourBoxes_mc.x+(displaceX*1.03); } } // function for Button function goUnderground(e:MouseEvent):void { gotoAndStop("underground_mc"); }Last edited by Maupa; May 31st, 2011 at 06:26 PM.

Reply With Quote


Bookmarks