I’m an AS3 noob who is trying trying to get more comfortable with passing arguments into functions. Can someone please help me understand why when the following code is all in one AS3 file as seen below it works and draws the purple square…
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var square_commands:Vector.<int> = new Vector.<int>(5,true);
square_commands[0] = 1;//moveTo
square_commands[1] = 2;//lineTo
square_commands[2] = 2;
square_commands[3] = 2;
square_commands[4] = 2;
var square_coord:Vector.<Number> = new Vector.<Number>(10,true);
square_coord[0] = 20; //x
square_coord[1] = 10; //y
square_coord[2] = 50;
square_coord[3] = 10;
square_coord[4] = 50;
square_coord[5] = 40;
square_coord[6] = 20;
square_coord[7] = 40;
square_coord[8] = 20;
square_coord[9] = 10;
Fill(square_commands, square_coord);
}
public function Fill(a:Vector.<int>,b:Vector.<Number>){
import flash.display.*;
graphics.beginFill(0x442266);//set the color
graphics.drawPath(a, b);
}
}
}
However, when I divide up the code into two AS3 files and try to pass the arguments to the function as follows…
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var square_commands:Vector.<int> = new Vector.<int>(5,true);
square_commands[0] = 1;//moveTo
square_commands[1] = 2;//lineTo
square_commands[2] = 2;
square_commands[3] = 2;
square_commands[4] = 2;
var square_coord:Vector.<Number> = new Vector.<Number>(10,true);
square_coord[0] = 20; //x
square_coord[1] = 10; //y
square_coord[2] = 50;
square_coord[3] = 10;
square_coord[4] = 50;
square_coord[5] = 40;
square_coord[6] = 20;
square_coord[7] = 40;
square_coord[8] = 20;
square_coord[9] = 10;
Fill(square_commands, square_coord);
}
}
}
and…
package{
import flash.display.*;
public class Fill extends Sprite{
public function Fill(a:Vector.<int>,b:Vector.<Number>){
graphics.beginFill(0x442266);//set the color
graphics.drawPath(a, b);
}
}
}
Flash CS5 gives me an error message 1137 saying that it was expecting only 1 argument in the code line –> Fill(square_commands, square_coord);
Could someone please explain how I need to pass the arguments square_commands and square_coord into the function in the second AS3 file?
Thanks in advance for all the help!!!
I suggest you read up on OOP and learn it if you are going to do lots of coding.