PDA

View Full Version : importing and including class and functions



kalyman
July 12th, 2009, 08:18 AM
Hey guys, am new to flash and am trying to create simple program, I kinda know how to code the program but its really difficult to interpret everything into action script.

For example I created class file in file node.as



class node {
var x:Number;
var y:Number;
var parx:Number;
var pary:Number;
var G:Number;
var H:Number;
var F:Number;

//---------------------------------------------------------
function node() {
this.x=0;
this.y=0;
this.parx=0;
this.pary=0;
this.G=0;
this.H=0;
this.F=0;
}
}
and few other functions that i want to use in main function in findpath.as file

now every time i try to import class or include functions in main .fla file >>>

import node;
include "findPath.as"; its giving me errors >

5007: An ActionScript file must have at least one externally visible definition.

So the question is how do I import class and functions so I dont need to write everything into one .fla file?
Thanks for any help.

ill attach incomplete code to this post.

~Kal

453.0
July 12th, 2009, 08:26 AM
First of all, that's not the way a class is written in ActionScript 3.0. You have no package definition.


package
{
public class node {
var x:Number;
var y:Number;
var parx:Number;
var pary:Number;
var G:Number;
var H:Number;
var F:Number;

//---------------------------------------------------------
public function node() {
this.x=0;
this.y=0;
this.parx=0;
this.pary=0;
this.G=0;
this.H=0;
this.F=0;
}
}
}
Obviously, this will not solve all your problems but it will solve the #5007 error.
You should learn more about ActionScript before jumping into something like this. I don't know how much programming experience you have but you are definitely far from writing stuff the way it should be written in ActionScript.

Good luck.

kalyman
July 12th, 2009, 09:42 AM
First of all, that's not the way a class is written in ActionScript 3.0. You have no package definition.

ActionScript Code:

package
{
public class node {
var x:Number;
var y:Number;
var parx:Number;
var pary:Number;
var G:Number;
var H:Number;
var F:Number;

//---------------------------------------------------------
public function node() {
this.x=0;
this.y=0;
this.parx=0;
this.pary=0;
this.G=0;
this.H=0;
this.F=0;
}
}
}



Obviously, this will not solve all your problems but it will solve the #5007 error.
You should learn more about ActionScript before jumping into something like this. I don't know how much programming experience you have but you are definitely far from writing stuff the way it should be written in ActionScript.

Good luck.

Thanks a lot for your reply, I will look into it, have to read couple more things how to get everything done in actionscript. Its little bit different from othre languages I was using, but this is a start. :)