Results 1 to 7 of 7

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

  1. #1

    Pallete TypeError: Error #1006: value is not a function. Please help

    Hello,

    I've tried to figure out why this didn't work. Please maybe someone can help me out.
    This is my code: I have 4 buttons that are named btn1, btn2, btn3, btn4.

    if I do only trace(my_btn) it returns btn1, btn2, btn3, btn4. But when I try to tell them to stop on frame, it returns
    TypeError: Error #1006: value is not a function.
    at project_fla::MainTimeline/frame1()

    This is my code

    for (var i:int = 1 ; i <= 4 ; i++ ) {
    var my_btn = "btn"+i;
    trace(my_btn);
    my_btn.gotoAndStop(i);
    }

    Thanks in advanced..

  2. #2
    In your current code, my_btn is a string.
    and strings don't have a gotoAndStop() method.
    try accessing it like this:
    this[my_btn]
    instead of
    my_btn
    as that will be an object of the container.

  3. #3
    What are you trying to do? Because the for loop looks kinda weird imo.

  4. #4
    His buttons might be instances of a multiframe MovieClip, with each unique button graphic on a different frame.
    ie: the loop creates frame1 button, frame2 button, etc...

    The loop isn't quite right for this though; it should be based on the totalFrames property of the MovieClip, instead of a hardcoded number.
    I would also not use instance names for the buttons; instead, wrap all of the buttons in a MovieClip, then loop through the MovieClip children. you can then reference them as child MovieClips by index, instead of by specific Strings.
    This method processes faster, and is immune to the errors inherent to String references.
    Last edited by snickelfritz; December 28th, 2011 at 04:02 PM.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

  5. #5
    Quote Originally Posted by TheVoid View Post
    In your current code, my_btn is a string.
    and strings don't have a gotoAndStop() method.
    try accessing it like this:
    this[my_btn]
    instead of
    my_btn
    as that will be an object of the container.
    Thanks a lot it works!
    for (var i:int = 1 ; i <= 4 ; i++ ) {
    var my_btn = "btn"+i;
    trace(my_btn);
    this[my_btn].gotoAndStop(i);
    }

  6. #6
    Quote Originally Posted by snickelfritz View Post
    His buttons might be instances of a multiframe MovieClip, with each unique button graphic on a different frame.
    ie: the loop creates frame1 button, frame2 button, etc...

    The loop isn't quite right for this though; it should be based on the totalFrames property of the MovieClip, instead of a hardcoded number.
    I would also not use instance names for the buttons; instead, wrap all of the buttons in a MovieClip, then loop through the MovieClip children. you can then reference them as child MovieClips by index, instead of by specific Strings.
    This method processes faster, and is immune to the errors inherent to String references.
    I have only a few buttons, so I prefer doing it this way. Maybe it's not perfect but it works. My as3 knowledge is quite basic so I stick with what I already know meanwhile

  7. #7
    BTW, I like the method you're using to construct buttons.
    There are some cool tricks you can use to improve the functionality of this method.
    For example, each frame of the button movieclip can contain variables that can be passed to the code on the main timeline.
    For example, movieClip class name, external file url, hex color value, etc... these values become custom properties of the button, and accessible in a mouse event handler with e.target.<propertyname>

    I use this method frequently with imported layered Photoshop and Illustrator files.
    For example, I have an Illustrator File of a USA map, with each state on its own layer.
    Import to the stage in a new MovieClip with layers to keyframes, loop through the MovieClip to wrap each keyframe in a MovieClip and assign mouse event listener/handlers, add them all to a new Sprite, and voila! Basic interactive map of the USA in a few minutes.

    Another use is for quickie photo galleries.
    Use the File>Script>load into stack... in Photoshop, to load a number of photos as layers in a new PSD.
    Change the imagesize to match your desired maximum scale for the Flash app.
    Save the PSD and import it to the stage in a new MovieClip in Flash. Layers to keyframes, etc...
    Loop through the keyframes, wrap each bitmap in a MovieClip, scale it down to thumbnail size, add listener/handlers to each, then position them in a grid in a nested loop.
    Basic interactive photo grid in a few minutes.
    I used to be a paranoid-psychotic-schizophrenic, but don't worry, he's dead now.

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