PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Button inside Movieclip (AS3)
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Button inside Movieclip (AS3)

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2

    Button inside Movieclip (AS3)

    I'm sorry if this is a dumb question, I'm still very new to this.

    I have a movie clip on my main timeline (instance name graphicLayer). In that movie clip, I have different graphics on the timeline depending on the frame. In one frame, there is a button (instance name urb_btn) and I would like that button to take you back to frame 1 of the graphicLayer movie clip.

    I hope that made sense.

    Here is my code thus far:
    Actionscript Code:
    //variables
    var frameNumber:uint;


    //station stop 1
    function stationStop1H(event:MouseEvent) {
        if (frameNumber > 400){
            frameNumber = frameNumber;
        } else {
            frameNumber = 6;
        }
        graphicLayer.gotoAndPlay(frameNumber);
    }
    function stationStop1C(event:MouseEvent) {
        if (frameNumber > 400){
            frameNumber = 6;
        } else {
            frameNumber = 401;
        }
        graphicLayer.gotoAndPlay(frameNumber);
    }
    function stationStop(event:MouseEvent) {
        if (frameNumber > 400){
            frameNumber = frameNumber;
        } else {
            frameNumber = 1;
        }
        graphicLayer.gotoAndPlay(frameNumber);
    }

    //station buttons
    station1_btn.addEventListener(MouseEvent.MOUSE_OVER, stationStop1H);
    station1_btn.addEventListener(MouseEvent.MOUSE_OUT, stationStop);
    station1_btn.addEventListener(MouseEvent.CLICK, stationStop1C);

    //button in station 1
    function stationHome(event:MouseEvent) {
        graphicLayer.gotoAndPlay(1);
    }

    graphicLayer.urb_btn.addEventListener(MouseEvent.CLICK, stationHome);

    There's a button on the main stage (instance name station1_btn) that when you click it, the movie clip (graphicsLayer) goes to frame 401. At frame 401, another button appears (urb_btn) that is supposed to take you back to frame 1 of the movie clip, but that doesn't work. Everything else works except for the button (urb_btn).

    I'm getting this output:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at hoops_04_fla::MainTimeline/frame1()

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    urb_btn does not exist at the time you are trying to add the event listener to it. You either have to make it exist the whole time, or delay adding the listener until it does exist.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    2
    Awesome. Thank you for your support. That didn't even occur to me, I'm trying to learn this as I go along. I got it working now.

    Thank you so much!

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center