Using internal in package gives error - actionscript-3

I'm trying to place a class into a package where another public class is placed. The documentation says that only one external visible declaration can be put in a package.
So i declare the second class internal. But then it gives the following error:
5006: An ActionScript file can not have more than one externally visible definition: character.AnimatedCharacterClass, character.CharacterPositions
The code I use is:
internal class CharacterPositions
{
public static const BEGIN_WALK:String = 'begin_walk';
public static const END_WALK:String = 'end_walk';
public static const STAND:String = 'stand';
}
Does anyone have a clue what is happening here?

I found that i have to put the second class outside the package. It still confuses me though.

Related

FLEX: Public Static Constant not imported, undefined

I'm trying to update a small Flex AS3 "project" consisting of one main file and an imported AS3 class. Unfortunately during compile I get the error 1120:Access of undefined property DEBUG. and the compilation fails. I've used mxmlc from Flex SDK 4.6 and Flash Builder 4.5 and get the same failure.
Flex isn't my strong suit so I hope someone can point out the error. From what I understand this source code compiled fine in 2011 using mxmlc.
Relevant code from the imported file:
package {
public class krpano_as3_interface {
public static var instance:krpano_as3_interface = null;
.
.
static public const STARTDEBUGMODE : int = 0xFF;
static public const DEBUG : int = 0;
And From the main AS3 file:
package {
.
import krpano_as3_interface;
public class soundinterface extends Sprite {
static public var krpano : krpano_as3_interface = null;
.
public function soundinterface() {
if (stage == null){
}else{
txt.htmlText = "krpano " + DEBUG::version + "\n\n" +
"<b>soundinterface plugin</b>" +
"\n\n(build " + DEBUG::builddate + ")";
}
}
If I rename or move the imported file the compiler complains that it is missing. The class where the constant DEBUG is defined should be being imported so why isn't it working?
The class where the constant DEBUG is defined should be being imported so why isn't it working?
Because they have nothing to do with each other.
DEBUG::version
and
static public const DEBUG : int = 0;
Are two unrelated parts of your code.
There are two hints in the syntax:
the :: name qualifier operator stands after a namespace, so whatever DEBUG is, it is a namespace, which the public static const is not (it's an int)
A property version is accessed. The public static const does not
have such a property.
What you are looking at is conditional compilation, which (among other things) allows you to specify values and pass them to the compiler to perform the compilation process.
You can also pass Strings and Numbers to the application and use them as inline constants
In your case, you want to define a version constant in the compiler arguments. Something like this:
-define+=DEBUG::version,"5"
This is probably because the version number is maintained by some build script (make, ant, whatever) and therefore passes this information to the compiler.
I highly recommend that you get in contact with the developer who worked on this project before to understand how the build process of this project is supposed to work.

Call to a possibly undefined method '' through a reference with static type Class

I made small .fla file in Flash Professional, and I have added .as (ActionScript File) in Flash Professional, and I have added something like code below to .as (ActionScript file), but the error appears and I am trying to figure it out, but can't, so I decided to post it in here instead.
package
{
import flash.display.MovieClip;
public class Bag extends MovieClip
{
static var firstBag:String;
public static function set setFirstBag(value:String):void
{
firstBag = value;
}
public static function get getFirstBag():String
{
return firstBag;
}
}
}
and I called it like this:
button1.addEventListener(MouseEvent.CLICK, onClickFirstButton);
function onClickFirstButton(e:MouseEvent):void
{
Bag.setFirstBag("First slot in the bag has been filled up!");
}
But I have received this following error:
Call to a possibly undefined method setFirstBag through a reference
with static type Class.
What could I do wrong?
The .as file and .fla file are on the same folder.
if I changed the Bag class to static. The error will be like this:
The static attribute may be used only on definitions inside a class.
Your answer much appreciated!
Thank you!
You're useing get like it is a mettod, but thay are accessors for properties so intead of:
Bag.setFirstBag("First slot in the bag has been filled up!");
use
Bag.setFirstBag ="First slot in the bag has been filled up!";
A few additional thoughts...
While syntactically valid, the definition and naming of your getter and setter is confusing and atypical, which I think contributed to your confusion about the behavior. You've actually defined two separate properties, one is write-only ("setFirstBag") and one is read-only ("getFirstBag"). Usually you define a getter/setter as the same property (ex "firstBag"), and without any "get" or "set" in the property name, since that is what the getter/setter is defining for you. Example:
private static var _firstBag:String;
public static function get firstBag():String {
return _firstBag:
}
public static function set firstBag(value:String):void {
_firstBag = value;
}
// usage
Bag.firstBag = "stuff";
trace(Bag.firstBag); // "stuff"
Also, you may very well have a good reason to use a getter/setter here, or you might just prefer it, but from the code you posted you could just define a public static var to do the same thing. (If you did, refactoring into a getter/setter if you needed some side-effect logic would be trivial, since the public API remains the same.)

Target main .as file in ActionScript 3

I am trying to target a variable in the main .as file (The one that acts as the stage) from another .as file.
public var stageRef:MovieClip = root as MovieClip;
or
MovieClip(root)variable = 10;
don't seem to want to work for me. Neither of them produce any compile errors but when I try to use them they give me a 1009 error, cannot access a property or a null object reference. Any ideas of how i would go about doing this? Thanks in advance.
Im your Main.as class make the variable public. Here's an example:
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public var YOUR_VAR_HERE:VARIABLE_TYPE = DEFAULT_VALUE;
public function Main()
{
}
}
}
DEFAULT_VALUE is optional. VARIABLE_TYPE is recommended, if not specified the type will be Object by default.
There are many ways to pass a variable to another class. If the class is created inside the Main class, just pass the variable to that class like this:
var myOtherClass:OtherClass = new OtherClass(YOUR_VAR_HERE);
or
var myOtherClass:OtherClass = new OtherClass();
myOtherClass.varReference = YOUR_VAR_HERE;
In first case make sure the constructor is expecting a variable. In the second, make sure the OtherClass has a public variable varReference that you can access and modify.
Another way loved by newbie programmers are static (singleton) variables: in the Main class specify your variable as such:
public static var YOUR_VAR_HERE:VARIABLE_TYPE = DEFAULT_VALUE;
Then you can access YOUR_VAR_HERE simply by referring to the class Main. Like this:
trace(Main.YOUR_VAR_HERE);
NOTE: it's considered to use all uppercase letters for constants, not variables, in this case I used all caps for readability.

"Could not find symbol"

I'm trying to embed an swf file in this way:
[Embed(source="../assets/assets.swf", symbol="main")]
public var MC:Class;
However, it keeps saying that error, "Could not find symbol main in...".
I've checked that the linkage of the symbol is indeed main.
What else should I check?.
Thanks.
(the file is found, if I remove the embed I can add the entire swf to the stage without problems)
I see nothing wrong with your syntax. The only place that you could be making a mistake is the name of the symbol. Use the ApplicationDomain.getDefinition() and ApplicationDomain.getQualifiedDefinitionNames() APIs to verify that the symbol name is correct.
The other problem might be that the file that contains the symbol is in a different location from the one being embedded. It sounds dumb, but I've done worse things when working on a tight deadline.
Example1:
if structure folder is
src(folder)
--core
-- Assets.as
assets(folder)
-fly01.png
The error because the directory path not extracly ( asset folder outside core folder)
Asset.as you write error:
package core
{
import starling.textures.Texture;
public class Assets
{
[Embed(source="assets/sky.png")]
private static var sky:Class;
public static var skyTexture:Texture;
}
}
Asset.as you write:error
package core
{
import starling.textures.Texture;
public class Assets
{
[Embed(source="../assets/sky.png")]
private static var sky:Class;
public static var skyTexture:Texture;
}
}
Asset.as you write:true
package core
{
import starling.textures.Texture;
public class Assets
{
[Embed(source="../../assets/sky.png")]
private static var sky:Class;
public static var skyTexture:Texture;
}
}

Can't use static const as param in function call within binding tags in Flex 3

I'm having a problem in flex 3 where if a static const I have defined is used as the parameter to a function call within binding tags I get a "1120: Access of undefined property NodePropertyMatrix". _propMtx is a ArrayCollection.
<mx:HBox visible="{_propMtx.getItemAt(NodePropertyMatrix.srcParent)}">
Above code throws the error, but the following code does not
<mx:HBox visible="{NodePropertyMatrix.srcParent}">
NodePropertyMatrix is an AS class as follows:
package model.constants
{
import mx.collections.ArrayCollection;
public class NodePropertyMatrix
{
public static const srcParent:Number = 0;
}
}
Anyone know what is wrong here?
Found the problem.
In the mxml file where I was importing the NodePropertyMatrix is was doing this:
import Constants.*;
Instead of this:
import Constants.NodePropertyMatrix;
For some reason it doesn't work in this instance without explicity importing that class. Wildcard didn't do the trick....not sure why, but ignorance is bliss.