A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: choose your own adventure: mystery issue

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    12

    choose your own adventure: mystery issue

    Situation:

    I'm trying to basically make a "choose your own adventure" type of animation, which is going to explain various parts of a painting.

    First there is a stopped frame with a play button on it.
    That button plays an animated introduction (if you want to skip the intro, you simply click anywhere on the screen and it'll bring you to the menu).
    You end up at a menu with various options to go to.

    I got the first and second part to work, now I am designing the menu. Before I do that I wanted to test if my "restart" button worked (a button that brings you to frame one again).
    it does bring you back to frame 1; HOWEVER, the play button no longer works...??? there are no compiler errors or output messages.

    Here is my script for the first frame (frames 1-9 actually):
    PHP Code:
    import flash.events.MouseEvent;
    import flash.media.SoundMixer;

    SoundMixer.stopAll()

    function 
    introBtnClick(evt:Event):void{
        
    gotoAndPlay("intro");
    }

    introBtn1.addEventListener(MouseEvent.CLICKintroBtnClick); 
    Here is my script for the animated intro (frames 10-19). The first frame has a movieclip nested into it:
    PHP Code:
    import flash.events.MouseEvent;
    import flash.media.SoundMixer;

    function 
    menuBtn1Click(evt:Event):void{
        
    gotoAndPlay("menu")
        
    SoundMixer.stopAll();
    }

    menuBtn1.addEventListener(MouseEvent.CLICKmenuBtn1Click); 
    And here's my script for the menu section:
    PHP Code:
    import flash.events.MouseEvent;

    function 
    restartBtnClick(evt:Event):void{
        
    gotoAndPlay("restart")
    }

    restartBtn.addEventListener(MouseEvent.CLICKrestartBtnClick); 

    note: funny thing is, the script for the play intro button and the invisible skip into button are the same, simply with different labels and instance names. If I direct the restart button to the intro animation, it works fine (and the invisible "skip intro" button works as well). What the deal!!!???

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    I forgot to mention one important thing.
    I have my stop(); command on another layer and on frame 2. when I put it at the top (of the script that I put on the first frame) I get the following error:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at Puppeteer_noAS_fla::MainTimeline/frame1()
    at flash.display::MovieClip/gotoAndPlay()
    at Puppeteer_noAS_fla::MainTimeline/restartBtnClick()

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    this is getting a little more frustrating. I started from scratch and did a mock-up without using all the fancy artwork and sounds, etc. it seems that all the scripting is the same and it is working. I will attach the simplified version.

    now I'm just stuck at how to make it go to the menu without repeating the animation. since I'm using AS3, I can't use any of the _root or _level0 stuff I found online!
    Attached Files Attached Files
    Last edited by pbars319; 03-08-2010 at 04:33 AM.

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function playBtnClick(evt:Event):void {
    	if (viewedIntro==false) {
    		gotoAndPlay("intro");
    	} else {
    		gotoAndPlay("menu");
    	}
    }
    playBtn.addEventListener(MouseEvent.CLICK, playBtnClick);
    Code:
    var viewedIntro:Boolean=true;
    function skipBtnClick(evt:Event):void {
    	gotoAndPlay("menu");
    }
    skipBtn.addEventListener(MouseEvent.CLICK, skipBtnClick);

  5. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    thanks for the help, but I need to be a little more clear (maybe I'm just understanding the scripting incorrectly, but I want the play button to always go to the intro, and if they want to skip it to click anywhere on the screen.
    right now the part that dosn't work is that what I go from the restart button (that goes from the menu to the first frame), the play button doesn't work the second time.

    however, it seems to work on the sample file I uploaded without the fancy artwork and sounds.

    additionally, I need to know how to have the intro go to the menu when it reaches the end. right now the closest thing I have is that they have to click on the stopped last frame, and then they can go to the menu, however, it'll be nice if they didn't have to use a button.
    (right now, my button is a layer on top of the one with the movieclip nested into it)

    THANKS!!

  6. #6
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function skipBtnClick(evt:Event):void {
    	gotoAndPlay("menu");
    }
    skipBtn.addEventListener(MouseEvent.CLICK, skipBtnClick);
    
    // give animation moive clip instance name, 'introAnimMC'
    
    introAnimMC.addEventListener(Event.ENTER_FRAME, chkAnimDone);
    function chkAnimDone(e:Event):void {
    	if (e.currentTarget.currentFrame==e.currentTarget.totalFrames) {
    		e.currentTarget.removeEventListener(Event.ENTER_FRAME, chkAnimDone);
    		e.currentTarget.stop();
    		e.currentTarget.parent.play();
    	}
    }

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    awesome! I'll check to see how this works out for me.


    any idea's as to the null object reference error message?

    I triple and quadruple checked that the same scripting I used for the simple file that I posted was the same for the real project and the simple one works fine.

    is there and way that the symbols I used in the animation to effect how the script is interpreted? are there any names I should stay away from?

    THANKS again.

  8. #8
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    Thanks for all your help. the scripting works perfectly for the intro on both the small test file and on the actual project. however, when using the same scripting for the next part of the project, I had to change

    e.currentTarget.parent.play();

    to

    e.currentTarget.parent.gotoAndPlay("menu");

    because i had to tell it to go backwards.
    flash doesn't seem to like that idea and keep getting null object references.
    perhaps I'm doing something else wrong. attached is the simple file. after this part is working (and I figure out why the restart button is not working on the actual project but is on the simple project), I theoretically should be able to finish this project on time.

    THANKS AGAIN!!! I don't know what I would do without the flashkit forum!
    Attached Files Attached Files

  9. #9
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    ovalAnim2MC.addEventListener(Event.ENTER_FRAME, chkAnim2Done);
    function chkAnim2Done(e:Event):void {
    	if (e.currentTarget.currentFrame==e.currentTarget.totalFrames) {
    		//e.currentTarget.removeEventListener(Event.ENTER_FRAME, chkAnimDone);
    		e.currentTarget.removeEventListener(Event.ENTER_FRAME, chkAnim2Done);
    		e.currentTarget.stop();
    		e.currentTarget.parent.gotoAndPlay("menu");
    	}
    }

  10. #10
    Junior Member
    Join Date
    Mar 2010
    Posts
    12
    wow... thanks.

    I'm glad I made a beginners mistake. It helps me think I'm not crazy (although it may be true, given the evidence that I took on this project)

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