views:

34

answers:

1

i've only ever created external .as files that extended a class such as sprite. now i just want to create one that doesn't extend anything and call it from a frame script.

package
{
public class Test
    {
    public function Test(val:Number, max:Number)
        {
        trace(val, max);
        }
    }
}

from my frame script of an .fla that is in the same folder as Test.as, i'll write this:

Test(50, 100);

this produces the following error:

1137: Incorrect number of arguments.  Expected no more than 1.
+1  A: 

Your code will be interpreted as cast to Test. It makes no sense to cast 2 numbers as a Test object.

What you want is an instance (an object) of the class Test.

For this, you need the new operator.

var testInstance:Test = new Test(50,100);

Then, you can use your object as needed, for example, calling methods, setting or getting values, etc.

testInstance.someMethod("hello");
testInstance.someNumber = 10;
var n:Number = testInstance.someNumber;
//  etc...
Juan Pablo Califano
clearly my coffee hasn't kicked in yet. wow. i'm confident this tops my all time most stupid questions. once again, thanks.
TheDarkInI1978
Haha, no worries! Give Java a little time to sink in.
Juan Pablo Califano