Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-21-2008, 01:20 AM   #1
compsci
Registered User
 
Join Date: Jul 2007
Posts: 203
Default Error #1006: value is not a function

Hello all,

Been trying to solve this problem for weeks now and I am at my last fist full of hair - I hope someone can help me. Apologies for the messy code I am noob.

I think the problem may be that I am calling a function from an event handler:
ActionScript Code:
import flash.events.Event; import flash.events.NetStatusEvent; import flash.net.*; import flash.media.*; //global variables var nc:NetConnection; var ns:NetStream; var cam:Camera; var mic:Microphone; function onBWDone():void{} function connect():void { // create basic netConnection object nc = new NetConnection(); // connect to the local Red5 server nc.connect("rtmp://localhost/oflaDemo"); //trying to solve an error nc.client = this; //adding event listners -security one? nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); } function connectStream():void{ // create the netStream object and pass the netConnection object in the constructor ns = new NetStream(nc); ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorEventHandler); // setup some simple settings with the cam and mic for quality setupCameraMic(); } function netStatusHandler(event:NetStatusEvent):void {     trace(event.info.code);     switch (event.info.code) {         case "NetConnection.Connect.Success":             connectStream();             break;         case "NetStream.Play.StreamNotFound":             trace("Stream not found:");             break;     } } function asyncErrorEventHandler(event:AsyncErrorEvent):void {} function setupCameraMic():void {     // setup cam     cam = Camera.getCamera();     // setting dimensions and framerate     var iFps = cam.fps; //what if camera doesn't have a default     cam.setMode(320, 240, iFps);     // set to minimum of 70% quality     cam.setQuality(0,90);         // setup mic     mic = Microphone.getMicrophone();     mic.rate(44); }

The full Error:
TypeError: Error #1006: value is not a function.
at SimpleRecorder_fla::MainTimeline/setupCameraMic()
at SimpleRecorder_fla::MainTimeline/connectStream()
at SimpleRecorder_fla::MainTimeline/netStatusHandler()


I do get a NetConnection.Connect.Success though, if thats any help. But i don't get the security question where flash asks for access to webcam and mic.

Thanks all
compsci is offline   Reply With Quote
Old 06-21-2008, 01:53 AM   #2
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Microphone.rate is a property not a method.

mic.rate = 44;

NOT

mic.rate(44);



this is inside you "setupCameraMic" function
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 06-21-2008, 02:16 AM   #3
compsci
Registered User
 
Join Date: Jul 2007
Posts: 203
Default

Thank you very much!!

Why are actionscript errors so un-helpful?! Is there like a better compiler for AS3 since when I have used Java before the compiler will tell me exactly where the problem is, this error didn't even help.

One final question, i get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.media::Camera@2637a0b1 to flash.net.NetStream.
at SimpleRecorder_fla::MainTimeline/playClick()

Because i used this line:

ns.attachCamera(cam);

Instead of what i thought would work:

ns.attachNetStream(cam);

But i get an error?! Any help
compsci is offline   Reply With Quote
Old 06-21-2008, 03:27 AM   #4
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

The errors are usually pretty self explanatory:

Quote:
TypeError: Error #1006: value is not a function.
at SimpleRecorder_fla::MainTimeline/setupCameraMic()
at SimpleRecorder_fla::MainTimeline/connectStream()
at SimpleRecorder_fla::MainTimeline/netStatusHandler()
This says that through the path of starting function netStatusHandler, you called "connectStream" function, which called "setupCameraMic" function, in which the error #1006 occurred.

This error is that "some value is not a function". This basically says to me, you referenced something as if it were a function, but actually isn't. So before even looking at your code I though 2 things:

1) some function asking for a function got passed a processed function. I.E. passing Back.easeIn() to a Tween instead Back.easeIn.

2) some object had a property called as if it were a function, when it isn't.

ending a prop with () tells the compiler you want to run a function, this syntax can only be used on functions. So I just looked at your code and saw that you referenced a prop with function syntax... remove and done.



On to your new error:
Quote:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.media::Camera@2637a0b1 to flash.net.NetStream.
at SimpleRecorder_fla::MainTimeline/playClick()
This says to me that your error occurs inside of the funciton "playClick". So first go there.

Next it says Type coercion failed. Coercion by definition means to "use force or intimidation to obtain compliance"... In programming it means you are forcing an object to be something it is not.

Coercion is allowed, for instance you can coerce a Sprite into being a DisplayObject because Sprite inherits from DisplayObject. You never tell it to be a DisplayObject...

ActionScript Code:
//no coercion var mySprite:DisplayObject = new DisplayObject(); addChild(mySprite);

as opposed to:
ActionScript Code:
//coercion var mySprite:Sprite = new Sprite(); addChild(mySprite); //addChild asks for a DisplayObject, not a Sprite

so you are actually coercing it, because there is never any direct command to do so.

Another kind of coercion which is independent of the inheritance hierarchy is prim coercion. For instance coercing an integer into being a Boolean. 0 can be coerced into being "false" and any integer != to 0 can be coerced into being "true". Hence why the following works:

ActionScript Code:
var i:int = 0; if (!i) trace("i == zero");

Now you can't coerce things that don't logically make sense. A BitmapData is not a DisplayObject, you can't add it to the DisplayList because it has no data to it that would create a visual representation of it for the graphics engine to handle. Thusly you must submit it to a Bitmap to create a visual representation.

By adding BitmapData's to the DisplayList you are coercing it to be a DisplayObject and it fails. Though this actually passes a different error because it is a common type of coercion that the compiler understands and knows a more specific error to let you know exactly what is going on.

So back to your error:

I'm assuming "ns" is a Video object (Video is the only Class I know of off hand that has both attachCamera and attachNetStream as methods). attachCamera requires a Camera object as a parameter, where attachNetStream requires a NetStream passed as a parameter.

Camera can not be coerced into being a NetStream, because there is no similarity between the two code wise. Thusly the method would have no idea what to do with it.


Consider it like so. Say you had a function that asked for a DisplayObjectContainer and in it you created a shape and added it to the container. Now say you passed a basic DisplayObject like Shape to it... the method "addChild" does not exist on a Shape, thusly the method would fail.

ActionScript Code:
function someFunction( obj:DisplayObjectContainer ):void {     obj.addChild(new Shape() ); } var shp:Shape = new Shape(); someFunction(shp); //fails





[edit]
The regular compiler usually can only get as close as the method in which the error occurred. Sometimes it might tell you the line, but usually not.

If you want a more direct path to finding your error try running it in debug mode (ctrl+shift+enter in CS3), when an error fires it brings you directly to the class which contains the error and places an arrow next to the line in which it occurred. That's about as close as it will get you though.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!

Last edited by lordofduct; 06-21-2008 at 03:39 AM.
lordofduct is offline   Reply With Quote
Old 06-21-2008, 08:28 PM   #5
compsci
Registered User
 
Join Date: Jul 2007
Posts: 203
Default

WOW omg - thank you so much! I can't believe that was the error and after you explained i guess its a good error reporting system! I just didn't know how to read it! Thank you once again!

(A repping system is really needed on this forum!)
compsci is offline   Reply With Quote
Old 06-21-2008, 11:06 PM   #6
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by compsci View Post
WOW omg - thank you so much! I can't believe that was the error and after you explained i guess its a good error reporting system! I just didn't know how to read it! Thank you once again!

(A repping system is really needed on this forum!)
No prob man, and I think my reputation is good enough on this site with out some rep system.

I know a lot of us here help as much as we can, but I bet a lot of us would like to keep requests to a minimum.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 01-22-2010, 12:50 AM   #7
felipegm
Registered User
 
felipegm's Avatar
 
Join Date: Apr 2005
Posts: 27
Default

Hi

i'm having a similar problem, with Error #1006.

My parent movie is loading a child. At child's last frame, i try to call a function at root of parent movie. i'm calling the function like bellow:

Code:
(root as MovieClip).loadSWF();
But when running the parent movie, get the following error compiler:

TypeError: Error #1006: carrega is not a function.
at home_fla::MainTimeline/effectEnding()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at FlashEff2/dispatchEvent()
at com.jumpeye.flashEff2.text.glowingGroup::FETGlowin gGroup/::motionFinish()
at Function/http://adobe.com/AS3/2006/builtin::apply()
at com.jumpeye.transitions::TweenLite/complete()
at com.jumpeye.transitions::TweenLite/render()
at com.jumpeye.transitions::TweenLite$/updateAll()


Any help???
felipegm is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
one template, many looks? subquark ActionScript 1.0 (and below) 1166 10-29-2013 07:18 PM
too much knowledge required to take advantage of the beauty of extending classes dsdsdsdsd ActionScript 3.0 4 03-17-2008 09:53 AM
Ease parameter Clutchplate Simple Stuff (Newbies) 8 03-16-2007 12:21 PM
flash movie plays in browser too slow m1cky ActionScript 2.0 7 01-11-2005 09:11 PM
can't call a function from within itself, what's my alternative? Jessica lucidiastudios ActionScript 1.0 (and below) 9 11-26-2003 11:03 AM


All times are GMT. The time now is 04:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.