Results 1 to 7 of 7
-
December 28th, 2011, 07:11 AM #17Registered User
posts
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..
-
December 28th, 2011, 09:00 AM #257Registered User
postsIn 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.
-
December 28th, 2011, 10:38 AM #3
What are you trying to do? Because the for loop looks kinda weird imo.
-
December 28th, 2011, 02:32 PM #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 03:02 PM.
-
December 28th, 2011, 06:27 PM #57Registered User
posts
-
December 28th, 2011, 06:28 PM #67Registered User
posts
-
December 29th, 2011, 12:42 AM #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.

Reply With Quote



Bookmarks