dcsimg
A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 41

Thread: TypeError: Error #1006: value is not a function.

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

    TypeError: Error #1006: value is not a function.

    Hi I keep getting this error and have no idea and have had no luck attempting to fix it.

    Basically I have a movieclip with a load of buttons in it which will all eventually lead to different movieclips. When a button is pressed I want a movieclip to appear and play. The movieclip is on the stage.

    The problem i have is that when i click the link, this error message appears in the Output tab:

    TypeError: Error #1006: value is not a function.
    at plumonicconsonants_fla:ulmonicconsonants_1/buttonClick()
    So far my code is
    Code:
    import flash.events.MouseEvent;
    
    pbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    
    function buttonClick(e:Event):void
    
    {
      gotoAndStop("pmovie" (5));
       
       pbtn.enabled = true;
    Any help would be greatly appreciated.
    Also any simple methods of achieving my aim other than this method would be greatly received.
    Thank you

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    "pmovie" is a String. Strings are not functions. You cannot call "pmovie"(5), which is what your code is doing.

    What do you think "pmovie" is? What are you trying to do with the (5)?

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Oh ok. "pmovie" is the movieclip I'm trying to gotoAndStop on and the (5) was the frame I wanted it to stop on.
    How should this be done properly?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Code:
    pmovie.gotoAndStop(5);
    That assumes that pmovie is in scope.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Ah thank you. I feel dumb now. I knew this was the way but just could not remember. Thanks again.

  6. #6
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Another question,

    When this new movieclip appears who do i redirect back to the main movie clip?

    I tried,

    Code:
    function back(event:MouseEvent):void {
    MovieClip(root).gotoAndPlay(1);
    }
    
    backBtn.addEventListener(MouseEvent.CLICK);
    but get the error
    Symbol 'p - movie', Layer 'Layer 1', Frame 5, Line 7 1136: Incorrect number of arguments. Expected 2.
    Also,
    how would i implement another button which would show a different movie clip to the one above?

    I tried

    Code:
     import flash.events.MouseEvent;
    
    pbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    bbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    
    function buttonClick(e:Event):void
    
    {
      pmovie.gotoAndStop(5);
       pbtn.enabled = true;
      
     bmovie.gotoAndStop(5);
       pbtn.enabled = true;
    however this just brings back the bmovie for both buttons.

    Thanks again. I apologise if I'm making it sound more complaicated than it probably is.

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    When you use addEventListener, you need to tell it two things: 1. What event to listen for. And 2. What function to call when that event happens. You did not do 2.

    I did not understand the second question. Of course both buttons are doing the same thing, you are calling the same listener for both, which doesn't use any event properties or state to distinguish the cases.

  8. #8
    Junior Member
    Join Date
    May 2011
    Posts
    21
    So it should look like

    Code:
    stop();
    
    function back(event:MouseEvent):void {
    MovieClip(root).gotoAndPlay(1);
    }
    
    backBtn.addEventListener(MouseEvent.CLICK, back);
    if back is the function I want to run?

    and

    how would i go about structuring listeners which use event properties or states?

    thanks

  9. #9
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Yes to the first question.

    To the second, in an event listener, you have the event argument. Events all have target and currentTarget properties which tell you which object dispatched the event, and which is currently reacting to it. You can often use those to have one listener function apply to many different objects.

    By "state", I meant the state of variables defined outside the function. That could be anything at all. But basically, if you want to have the listener do things differently when it runs in different situations, you have to write it so that it actually does different things in different situations.

  10. #10
    Junior Member
    Join Date
    May 2011
    Posts
    21
    I understand what you're saying but could you perhaps provide an example?

  11. #11
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Sure. I don't know what sort of things pbtn and bbtn are here. If they are MovieClips, you can simplify this. If they are buttons, leave it as is.
    Code:
    var buttonToMovie:Dictionary = new Dictionary();
    buttonToMovie[pbtn] = pmovie;
    buttonToMovie[bbtn] = bmovie;
    
    pbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    bbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    
    function buttonClick(e:Event):void{
      var mov:MovieClip = buttonToMovie[e.currentTarget];
      mov.gotoAndStop(5);
    }

  12. #12
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks! Exactly what i needed, however the movieclip now appears behind the previous content. I've tried positioning using Arrange but no luck. Any idea why this may be?

  13. #13
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That code does not change the depth of the movie. If it is behind, it was behind before that code ran.

    You can bring it back to the front by adding it as a child again.
    Code:
    function buttonClick(e:Event):void{
      var mov:MovieClip = buttonToMovie[e.currentTarget];
      addChild(mov);
      mov.gotoAndStop(5);
    }
    That assumes that pmovie and bmovie were children of the instance which has this timeline code. But that's a pretty safe assumption as otherwise you'd have to have retrieved references to them somehow and you didn't mention that.

  14. #14
    Junior Member
    Join Date
    May 2011
    Posts
    21
    That worked perfectly.one more problem though, the back button is no longer taking me to its parent movieclip. it now does nothing despite not changing a single thing.

    Code:
    function back(event:MouseEvent):void {
    MovieClip(root).gotoAndStop(1);
    }
    
    backBtn.addEventListener(MouseEvent.CLICK, back);
    maybe its to do with the way my movie clips are set up?

    I have a movieclip named "pulmonic", which contains the "pmovie" movieclip in which the back button is placed. I want the back button to take me back to the first frame of the "pulmonic" moveiclip.

  15. #15
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Unless pulmonic is the root, that code won't affect it. Is this your structure?

    root -> pulmonic -> pmovie -> backBtn

    Since that code is in pmovie (right?), use parent instead of root. Although ideally what you'd do is actually dispatch a new bubbling event of a type you make up, and listen for that event in pulmonic. That would decouple your logic from your display setup.

  16. #16
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Yeah thats the structure. I tried parent but it was the same result as root. i.e. nothing. By bubbling event what do you mean? Example?

  17. #17
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Using parent instead of root should have worked if that is actually your structure. Are you sure that back is even getting called? Put a trace statement in to verify.

    By bubbling event, I mean something like this in pmovie:
    Code:
    function back(event:MouseEvent):void{
      dispatchEvent(new Event("BACK", true));
    }
    And this in pulmonic:
    Code:
    addEventListener("BACK", goBack);
    
    function goBack(e:Event):void{
      gotoAndStop(1);
    }

  18. #18
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Hmm still the same result. No trace is appearing in the output either. I've gone back and checked the structure and it's definitely root(scene1) > pulmonic > pmovie.

  19. #19
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If you put a trace in back, but no trace appears, then back is not getting called. Perhaps backBtn is not the instance you think it is. Or if you added the event listener in a different keyframe or scene, then the backBtn you added it to may have been replaced with another instance.

  20. #20
    Junior Member
    Join Date
    May 2011
    Posts
    21
    I've tried getting rid of the button and making a new one with the instance of simply "btn". Just to check the whole code for this should be:

    Pmovie:
    Code:
    function back(event:MouseEvent):void{
      dispatchEvent(new Event("BACK", true));
    }
    Pulmonic:
    Code:
    var buttonToMovie:Dictionary = new Dictionary();
    buttonToMovie[pbtn] = pmovie;
    buttonToMovie[bbtn] = bmovie;
    buttonToMovie[tbtn] = tmovie;
    
    
    pbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    bbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    tbtn.addEventListener(MouseEvent.CLICK,buttonClick);
    
    function buttonClick(e:Event):void{
      var mov:MovieClip = buttonToMovie[e.currentTarget];
      addChild(mov);
      mov.gotoAndStop(5);
    }
    
    addEventListener("BACK", goBack);
    
    function goBack(e:Event):void{
      gotoAndStop(1);
    }

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