AS3 Argument Error #1063 ... expected 1 got 0 - actionscript-3

So I got a very basic class
package {
import flash.display.MovieClip;
public class XmlLang extends MovieClip {
public function XmlLang(num:int) {
trace(num);
}
}
}
and an object at frame one:
var teste:XmlLang = new XmlLang(1);
I'm getting this error:
ArgumentError: Error #1063: Argument count mismatch on XmlLang(). Expected 1, got 0
What am I doing wrong?
Thank you very much for you help.

Something is up with your setup. I took your code and implemented it and it worked.
Here's what I did. I created a new test.fla file in AS3 and put the following code on frame 1 - no object on the stage, just code in frame 1.
import XmlLang;
var teste:XmlLang = new XmlLang(1);
stop();
Created a XmlLang.as file, copying your code exactly and saved it in the same folder as the test.fla. Compiled and got a trace of 1
So I'm not exactly sure what's going on. What version of Flash are you running?

Not sure if this was your case, but for future googlers: you get this error message when you're trying to initialize a vector but then forget the new keyword.
So this:
var something:Vector.<Something> = Vector.<Something>();
Will give you an error saying that Something had an argument count mismatch. The correct line is:
var something:Vector.<Something> = new Vector.<Something>();
Difficult error to get at a glance. Took me a few minutes to find it in my code, especially because it doesn't really give you the error line.

I expect you have an instance of XmlLang located on stage, that will be constructed using a constructor with 0 parameters, like an ordinary MovieClip. To check for this, change the constructor header to this:
public function XmlLang(num:int = 0) {
This way, if something will instantiate an XmlLang without a parameter supplied, the new instance will receive a 0 (the default value) as parameter. And then you check your trace output, I am expecting one or more zeroes appear, followed by an 1.

Related

TypeError: Error #1009: Cannot access a property or method of a null object reference. The object isn't null

Okay, so my game codes are not problematic at all and don't effect the game UNLESS I declare the level "OneManager" as a variable.
OneManager is the class for my level. The level is a movieclip containing all the level's components. And Main is the document class.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at OneManager()[C:\Users\Jay\Creative Cloud Files\Subject 51 Experimental\OneManager.as:38]
at Main()[C:\Users\Jay\Creative Cloud Files\Subject 51 Experimental\Main.as:16]
I don't think it makes any sense. I deleted line 38, then the problem indicated until line 39, then I deleted them over and over. Then practically until my code was useless, that's when I FINALLY got no error...
These codes don't even look problematic at all. I even tried adding them manually by adding the class's movieclip to the stage myself and it worked completely fine. But what I'm trying to do is add it to the stage through code by making this class's movieclip a variable and when the button is clicked, but if I did that - I would get these random errors from other classes.
I'm not sure what's wrong here. There is no trouble compiling, so I get no compile errors. Only errors from the output. These lines of codes aren't null, but the output says it is. I'm confused.
Please help, thanks!
Code for Main Document Class:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var mountains: Mountains;
var homePage: HomePage;
var oneManager: OneManager;
public function Main()
{
mountains = new Mountains;
homePage = new HomePage;
oneManager = new OneManager;
addChild(homePage);
homePage.playButtons.addEventListener(MouseEvent.CLICK, onPlayButtonsClick);
}
function onPlayButtonsClick(event:MouseEvent):void
{
//var level1Page = new Level1Page;
removeChild(homePage);
addChild(oneManager);
}
}
}

error message asking for Properties onMetaData when load external vdo BUT, vdo can play anyway

I'm trying to figure out how to remove the message error and what cause it.
I created a code for loading external vdo to play on Flash. Coding it inside the Action Script panel is fine so I try to make it as a class. I moved all the code and put it in a class and it works fine too. But, the error message appeared ! even though the file could play correctly.
The error says:
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on vdoloader and there is no default value.
at vdoloader()
This is my code
package {
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
public class vdoloader extends Sprite {
var video;
var nc;
var ns;
public function vdoloader() {
// constructor code
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.client=this;
video = new Video(550,400);
addChild (video);
video.attachNetStream(ns);
ns.play("westler.flv");
}
}
}
And then I tried to put something in that vdoloader(), it said something like: "expected 1, got 0."
It is exactly that - you are not handling the meta data event by implementing a function onMetaData. The client of your player is "this", so you should have a public function onMetaData in your class.
An please oh please, use an uppercase first letter for your class name...
EDIT:
In your code you are assigning this as the netstream's client (source: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html):
Associate a client property with an event handler to receive the data
object. Use the NetStream.client property to assign an object to call
specific data handling functions. The object assigned to the
NetStream.client property can listen for the following data points:
onCuePoint(), onImageData(), onMetaData(), onPlayStatus(),
onSeekPoint(), onTextData(), and onXMPData(). Write procedures within
those functions to handle the data object returned from the stream
during playback. See the NetStream.client property for more
information.
So now you just need to create a function onMetaData(md:Object) that should handle the event within the very same class, i.e. vdoloader (<=as you are passing this as the client). You can check the docs how to do it: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onMetaData. I think that Lee Brimelow had a tutorial about this on his site - http://www.gotoandlearn.com. (I am not sure about this but I guess it is worth a try if you are interested)

AS3 TypeError: Error #1009

I am trying to create a web application with multiple scenes, the error appears when I try to access the next scene with a button I created that contains multiple EventListeners for animation purposes.
The Button did bring me to the next scene, but the error still occurs. After tracing and debugging, the error seems to occur at the Mouse_Out event.
I am still very new to AS3, so can someone please explain to me where my code went wrong and if possible, correct the error for me or is there a better way of writting the code? Thanks in advance.
The Error Involved:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.transitions::Tween/setPosition()
at fl.transitions::Tween/set position()
at fl.transitions::Tween()
at Portfolio_fla::MainTimeline/about_btnOut()
My Code:
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
about_btn.buttonMode = true;
about_btn.mouseChildren = false;
about_btn.alpha = 0.3;
about_btn.addEventListener(MouseEvent.MOUSE_OVER, about_btnOver);
function about_btnOver(event:MouseEvent):void
{
var AboutAlphaOver:Tween = new Tween(about_btn,"alpha",Regular.easeIn,0.3,1,0.1,true);
}
about_btn.addEventListener(MouseEvent.MOUSE_OUT, about_btnOut);
function about_btnOut(event:MouseEvent):void
{
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
}
about_btn.addEventListener(MouseEvent.CLICK, about_btnClick);
function about_btnClick(event:MouseEvent):void
{
gotoAndPlay(1,"About");
}
Try to change your Tween code:
var AboutAlphaOut:Tween = new Tween(about_btn,"alpha",Regular.easeIn,1,0.3,0.1,true);
To:
var AboutAlphaOut:Tween = new Tween(event.currentTarget,"alpha",Regular.easeIn,1,0.3,0.1,true);
I'm not sure if it will work (I'm not too familiar with Flash IDE), but I think it's possible that you are getting error because other scene doesn't have a reference to a button. With event.currentTarget, you will search for reference in the event, so it should find it in any case.
BTW: You shouldn't name your variables starting by capital letter. That way you will more easily distinguish objects from classes.

MovieClip extension

I have been trying to develop a CustomButton class that extends MovieClip, however I am having problems. I have got this error:
ArgumentError: Error #1063: Argument count mismatch on
mkh.custombutton::CustomButton(). Expected 2, got 0. at
flash.display::Sprite/constructChildren() at flash.display::Sprite()
at flash.display::MovieClip()
I've tried to debug my code, but it says
"Cannot display source code at this location."
I am not sure where is the problem, but I suppose it's in the constructor:
public function CustomButton( buttonlabel:String, animationAR:Array, active:Boolean=true, animated:Boolean = false, type:String = "free", group:int = 0 )
I would be very grateful if anyone helped me. Thank you.
EDIT2: I think I know why it's not appearing, so nevermind.
Seems like you must be instantiating CustomButton without passing it any arguments.
Like so:
var cBtn = new CustomButton();
However, you constructor has 2 arguments that must be passed - buttonLabel and animationAR (the rest are OK because they are assigned a default value).
So you should be doing something like this:
var cBtn = new CustomButton('Test', someArray);
I think I know what the problem is, now I hope I can explain to you clearly enough (English is not my first language). Did you by any chance make a graphic MovieClip in the Flash program and linked it to your CustomButton class? If so, be careful with the instances you might have on the stage, because when Flash creates the Sprites/Movieclips objects that are on the stage it calls their constructor without any parameters.
To avoid this, either:
Set default values for all parameters in your CustomButtonClass (EDIT: which would solve your problem, but is not very good practice)
Use addChild to put instances of your Button onto the stage (I recommend this one)
Hope this helps!
public function CustomButton(
buttonlabel:String,
animationAR:Array,
active:Boolean=true,
animated:Boolean = false,
type:String = "free",
group:int = 0
);
That's how you defined your constructor. This means that the first 2 arguments (buttonlabel abd animationAR) are required arguments. The rest are optional.
Now if you try to instantiate this like
var cb:CustomButton=new CustomButton();
You are not passing any arguments to the constructot, which will throw that error.
Note that this is what happens when you create the object directly in the UI.
A way to fix this would be to redefine the constructor as:
public function CustomButton(
buttonlabel:String="CustomButton",
animationAR:Array=[],
active:Boolean=true,
animated:Boolean = false,
type:String = "free",
group:int = 0
);
This makes all arguments optional and should work. Of course, you'll be best off putting the default value of the arguments as something you know will work. For example, in my example, the empty array default for animationAR could break your code, in which case you need to add this to the constructor body:
if(animationAR.length==0) {
animationAR.push(new Animation());
//YOU WILL HAVE TO CHANGE THIS LINE TO CORRESPOND TO YOUR CODE
}
OR ELSE, you could instantiate the object as
var cb:CustomButton=new CustomButton("My Crazy-ass CustomButton", animArray);

Trying to connect to AMFPHP - NetConnection.connect() returns TypeError: Error #1009

UPDATE: Now I've moved the AMFConnection var declaration to outside the functions in Main, and commented out some trace() commands, and now it gives new errors:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.BadVersion
at AMFConnection/init()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:32]
at AMFConnection()[/Users/Jan/Downloads/amfphp1/AMFConnection.as:23]
at Main/testConnection()[/Users/Jan/Downloads/amfphp1/Main.as:14]
at Main()[/Users/Jan/Downloads/amfphp1/Main.as:10]
All of these essentially point to AMFConnection's NetConnection initialisation: _netConnection = new NetConnection(); (where _netConnection is declared at the beginning of the class)
I'm trying to connect to AMFPHP on a server (with Flash AS3), and the swf borks when it reaches the .connect() stage. To make things easier (?) and more reusable (?), I've put all the NetConnection mechanics into a separate class, AMFConnection, which I call from the Main document class like this (details changed):
public function testConnection(e:*=null):void {
var conn:AMFConnection = new AMFConnection();
conn.table = "some_table";
conn.selections = "*";
conn.conditionals = "WHERE something = 'something'";
conn.service = "QueryAMF";
conn.method = "makeQuery";
conn.displayText = txt;
conn.gogogo("http://www.someplace.com/Amfphp");
}
AMFConnection actually starts the connection and calls the AMFPHP service with the function gogogo(), and here's where the connect() NetConnection function just won't work. Here's the main section of the AMFConncection class
private var _netConnection:NetConnection;
private var _responder:Responder;
function AMFConnection()
{
init();
}
private function init(e:* = null)
{
_netConnection = new NetConnection();
_responder = new Responder(uponResult);
}
public function gogogo(url:String):void {
trace(url);
_netConnection.connect(url);
_netConnection.call(String(service+"/"+method), new Responder(onResult, null), table, selections, conditionals);
}
A quick debug session reveals the below errors:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AMFConnection/gogogo()[AMFConnection.as:44]
at Main/testConnection()[Main.as:20]
at Main()[Main.as:8]
Where: Main.as:20 = conn.gogogo(...), and AMFConnection.as:44 = _netConnection.connect(url);
It also fails to display the stage, instead showing the loading dots. Now, eventually I'm going to move this application to the same server as the AMFPHP service, but even when I try it there with a relative url, instead of an absolute one, it still breaks down at connect(). I've tried changing the publish settings from local only to network only, to no avail.
Any clues? Know a better way to connect to AMFPHP locally?
Cheers in advance!
JB
P.S. Post updated, see top of page.
first, i prefer to use a php file which contains my sql and params. but hey...
The most obvious reason why you might get this error would be a fault in the url i guess. I believe that the standaard gateway.php is written without a capital G. and does not situate itself in the core folder but in the amfphp folder. but then again I don't know what you have altered.
Your _netConnection must be null, and you call connect() method on null reference, so you finish with NullPointerException. Show us how you initialize _netConnnection :).
Ok, I basically remade the thing, and after a couple of hours, it decided to work. I'm not sure how, but... eh.
Thanks all for your help