Compiler error that makes me confused about ActionScript

First, I want to explain that I'm not familiar with ActionScript, so don't blame me too much for some basic mistakes. I just found out about this for a short while. As such, some advice on ActionScript scripting is always welcome. :)

I don't know why the compiler said the constructor of one of my classes does not take any parameters.

OK. You can get my point with the code shown below.

Here's Player.as:

public class Player extends Sprite
{
    public var mcHealthBar:HealthBar;
    public function Player()
    {
        // Here a compiler error is found.
        mcHealthBar = new HealthBar(max_health);
    }
}

      

and also HealthBar.as:

public class HealthBar extends MovieClip
{
    private var max_hp:int;

    public function HealthBar(MaxHP:int)
    {
        // constructor code
        max_hp = MaxHP;
    }
}

      

The compiler said the HealthBar constructor cannot be used with arguments, but you can explicitly see the HealthBar () constructor inside HealthBar.as already written with the MaxHP argument.

Finally, I want to ask, why is there a compiler error?

NOTE. I am coding using Flash-Builder and Flash-Professional together. I created a Flash-Professional project through Flash-Builder. I am drawing with Flash-Professional and code using Flash-Builder.

There may be misspellings in English grammar ... So I'm really sorry for my very poor English lol ...

+3


source to share


2 answers


This is usually the problem when I ran into this problem before:

HealthBar

most likely tied to a library object in FlashPro . (you exported it for actionscript and gave it a class name HealthBar

).

The problem is that FlashPro does not see the class file, so it generates one of its own (which has no constructor argument).

You can check if FlashPro sees the file by clicking the edit icon in the binding properties of the library object (see image). If a custom .as file appears, that's not a problem. Check to see if FlashPro sees your .as file

This is usually because the .as file is not in the correct location, or the package name is not appropriate for where the file physically resides.



If your file is .as

just using package {

, then by default the file should be placed in the same directory as the file .fla

.

If it was package bob {

, then it should be in a folder named bob (and the default folder will be in the same directory as .fla)

You can change where .fla looks for class files by going to ActionScript Preferences , which can be found in the file menu.

This window has a Source Path tab where you can add directories to search for .as files.

+2


source


You may have a problem with a library object that you named HealthBar and gave the class the same name. If the name is case, the HealthBarMC Library object and save the class with the same name and see if that works.



+1


source







All Articles