The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: MC with button to other page, doesn't work

  1. #1
    20
    posts
    Registered User

    Afrostyle 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.

  2. #2
    gotoAndStop(2); without the quotes

  3. #3
    20
    posts
    Registered User
    Oh 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.

  4. #4
    Is that extra space in CLICK actually in your code? Could that be the culprit?

    MouseEvent.C LICK, goUnderground

  5. #5
    Quote Originally Posted by Maupa View Post
    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?)
    ***
    this.underground_btn.addEventListener(MouseEvent.C LICK, goUnderground);

    root.function goUnderground(e:MouseEvent):void //or without root.
    {
    gotoAndStop("2");
    }
    ...
    A 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
    Code:
    this.houses_mc.underground_mc.addEventListener(MouseEvent.CLICK, goUnderground);  
    // NOTE: You do not need "this." at the beginning
    You will also probably want to do a few "basic" things usually done for turning MovieClips into buttons...
    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
    You also may run into a further issue so at the beginning of your code, you may want to put...
    Code:
    houses_mc.mouseChildren = true;
    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".
    Last edited by Josh Martin; May 31st, 2011 at 05:02 PM. Reason: Readability

  6. #6
    20
    posts
    Registered User
    @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.

    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");
    }
    I hope this helps someone to understand my issue in order to help me. I really stuck.
    Last edited by Maupa; May 31st, 2011 at 06:26 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012