Class variable AS3 problem
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
I'm trying to create a class to use as like a templae for sets of variables(players)
Here is my error message:Line 17, Column 31 1084: Syntax error: expecting rightparen before dot.
I have an .as (AS3) file "Classes" targeted to my .fla "Classes" with the code:
package
{
import flash.events.*
import flash.display.*
public class Classes extends MovieClip
{
public function Classes()
{
var guy:Person = new Person
guy.firstName = "Tim"
guy.idn = 2468642
printPerson(guy);
}
public function printPerson(p.Person);void
{
trace:( "NAME:" + p.firstName + " / ID#:" + p.idn )};
}
}
}
& here is the script for my "Person.as" file
package
{
import flash.events.*;
import flash.display.*;
public class Person extends MovieClip
{
var firstName:String;
var idn:int;
public function Person()
{
}
}
}
I've been practicing using this code off of a tutorial & I'm trying to gain all the information from it so I can learn to write my own codes, this is the only error message I can't fix on this code.. I'm not sure what it means by rightparen & dot.
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/17/13 05:32 PM, Raghoul wrote: public function printPerson(p.Person);void
You need a colon, not a dot. And you need a colon, not a semicolon.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
package
{
import flash.events.*
import flash.display.*
public class Classes extends MovieClip
{
public function Classes()
{
var guy:Person = new Person
guy.firstName = "Tim"
guy.idn = 2468642
printPerson(guy);
}
public function printPerson(p:Person):void
{
trace:( "NAME:" + p.firstName + " / ID#:" + p.idn )};
}
}
This is what I have now, no error messages but the trace didn't show up in my output.
- MintPaw
-
MintPaw
- Member since: Jun. 11, 2006
- Offline.
-
- Forum Stats
- Member
- Level 10
- Programmer
printPerson(p.Person);void
vs
printPerson(p.Person):void
trace:( "NAME:" + p.firstName + " / ID#:" + p.idn )};
vs
trace( "NAME:" + p.firstName + " / ID#:" + p.idn );
var guy:Person = new Person
vs
var guy:Person = new Person();
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
At 12/17/13 06:23 PM, Raghoul wrote: This is what I have now, no error messages but the trace didn't show up in my output.
You have more than one public item in your package.
A package must contain only one public item.
Everything else must either be outside of the package or inside classes.
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/17/13 06:23 PM, Raghoul wrote: This is what I have now, no error messages but the trace didn't show up in my output.
You're missing a "}". Go back in your code and find where the missing one belongs.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Now it's working
Classes.as
package
{
import flash.events.*;
import flash.display.*;
public class Person extends MovieClip
{
var firstName:String;
var idn:int;
public function Person()
{
}
public function personaldata():void
{
trace( "NAME: " + firstName + " / ID#:" + idn )};
}
}
Person.as
package
{
import flash.events.*;
import flash.display.*;
public class Person extends MovieClip
{
var firstName:String;
var idn:int;
public function Person()
{
}
public function personaldata():void
{
trace( "NAME: " + firstName + " / ID#:" + idn )};
}
}
So if I put all my created functions in different .as files in the same folder as my .fla.. Then when I exported my flash, would they all be part of my .swf & work properly as long as the AS in my .fla calls upon their function?
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/17/13 06:58 PM, Raghoul wrote: So if I put all my created functions in different .as files in the same folder as my .fla.. Then when I exported my flash, would they all be part of my .swf & work properly as long as the AS in my .fla calls upon their function?
Yes. I was mistaken before, I didn't realize you had a } after the trace. But you don't put semicolons after } usually. You might want to change the white space to make your code more readable like:
package {
public class Person() {
public function Person() {
}
public function personaldata():void {
}
}
} - Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
So can I call upon these functions (.as files) using the actionscript in my .fla (game) & they will work in my exported movie?
How about when I publish it, will these .as files with functions be a working part of my .swf?
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/17/13 08:56 PM, Raghoul wrote: So can I call upon these functions (.as files) using the actionscript in my .fla (game) & they will work in my exported movie?
How about when I publish it, will these .as files with functions be a working part of my .swf?
I said yes already.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
I see, I only truly tried to learn the basics of actionscript today, before I just had some scripts saved to make play buttons & such so I could get by with my movies, but now I am starting to understand variables
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
At 12/17/13 09:17 PM, Raghoul wrote: I see, I only truly tried to learn the basics of actionscript today, before I just had some scripts saved to make play buttons & such so I could get by with my movies, but now I am starting to understand variables
So your problem is solved. Good.
Awaiting whatever you come up with next.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
So I think I can make a new .as file for every character in the game.. Each .as file will be a copy(template) of an array of variables containing the character's base stats. So I think it could work if I reference the characters .as file(stat template) to load their base stats into the game, but stat upgrading will be done in the .fla
I'm trying to make a turn based game, it seems like I could eventually pull it off because it's just animations(named frames)/buttons/variables
I have animation experience because that's basically all I've done, so luckily I basically am just focusing on learning programming, the more I learn the more ideas I get & the more interested I get.
- MSGhero
-
MSGhero
- Member since: Dec. 15, 2010
- Offline.
-
- Forum Stats
- Supporter
- Level 16
- Game Developer
At 12/17/13 09:31 PM, Raghoul wrote: So I think I can make a new .as file for every character in the game.. Each .as file will be a copy(template) of an array of variables containing the character's base stats. So I think it could work if I reference the characters .as file(stat template) to load their base stats into the game, but stat upgrading will be done in the .fla
Since you're making classes, you can make variables. There's no sense having an array of numbers when you could give them names like "health," "damage," and stuff. Under step 10 here, but the entire article is very useful to know.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
This is the function I am trying to do (File: ShowStats.as)
package
{
import flash.events.*;
import flash.display.*;
public class ShowStats extends MovieClip
{
public class BaseStatsLists
{
BaseStats.push( "Name: " );
BaseStats.push( "Attack: " );
}
}
public function ShowBaseStats():void
{
for( var i:int = 0; i < 2 ; i++ )
{
trace( BaseStats[i] );
}
}
}
BaseStatsLists.as
package
{
import flash.events.*;
import flash.display.*;
public class StatList extends MovieClip
{
var BaseStats:Array = new Array();
BaseStats.push(var Name:String) var Name = Character;
BaseStats.push(var Att:int) var Att = 0;
}
}
errors in BaseStatsLists.as
Line 9, Column 18 1084: Syntax error: expecting identifier before var.
Line 9, Column 26 1084: Syntax error: expecting rightparen before colon.
Line 9, Column 34 1084: Syntax error: expecting rightbrace before rightparen.
- Sam
-
Sam
- Member since: Oct. 1, 2005
- Offline.
-
- Forum Stats
- Moderator
- Level 19
- Programmer
At 12/17/13 11:02 PM, Raghoul wrote: Line 9, Column 18 1084: Syntax error: expecting identifier before var.
Line 9, Column 26 1084: Syntax error: expecting rightparen before colon.
Line 9, Column 34 1084: Syntax error: expecting rightbrace before rightparen.
By the look of it you need to take a step back and learn correct syntax before attempting anything. There are various basic syntax errors wrong with your classes.
- kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
At 12/18/13 03:25 AM, Sam wrote:At 12/17/13 11:02 PM, Raghoul wrote: Line 9, Column 18 1084: Syntax error: expecting identifier before var.By the look of it you need to take a step back and learn correct syntax before attempting anything. There are various basic syntax errors wrong with your classes.
Line 9, Column 26 1084: Syntax error: expecting rightparen before colon.
Line 9, Column 34 1084: Syntax error: expecting rightbrace before rightparen.
Packages and namespaces
List of keywords, namespaces, directives
Example:
public class something{
or
internal var p:Number=3;
or
public static function get length():Number{
etc
Sources:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/ (see Language Elements in top-right scrolling field)
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Thanks I was looking for a basically explained keyword list, basic explanations are the best because you can learn & build off of it faster & easier.
- Raghoul
-
Raghoul
- Member since: Dec. 17, 2013
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
Now I'm wondering about this:
My Player is an undefined property(variable) & I'm not sure why.
Classes.as
package
{
import flash.events.*
import flash.display.*
public class Classes extends MovieClip
{
public function Classes();
{
var Player:Person = new Person();
Player.Name = "Fred";
trace("Name: " + Player.Name);
}
}
}
Person.as
package
{
import flash.events.*
import flash.display.*
public class Person extends MovieClip
{
var Name=String;
public function Person();
}
} - kkots
-
kkots
- Member since: Apr. 16, 2013
- Offline.
-
- Forum Stats
- Supporter
- Level 10
- Blank Slate
If you do not know how to properly define variables and functions and classes, please, pretty please, first read and understand the info that I gave you in links that I posted as "Sources" - everything about ActionScript 3 syntax is explained right there. You're having problems with basic syntax.
Please, use those links as references, and do not post on forums asking for help, until you get the syntax right and until your example class stops making any errors.

