Search code examples
actionscript-3flashadobelinker-errors

Importing a Package in Adobe Flash CS3 - Pointless Messages from "Access of Undefined Property" to none at all


I inherited a Flash CS3 legacy app and I am trying to refactor it a little. Eventually everything is supposed to be moved over to JS, but for now I would like to start working with what I have rather than attempting a complete rewrite. First I would like to install a little regression test.

I am trying to setup the test in it's own package in order to reducing the seams it has with the original app. The app uses a lot of global variables and I wish not to interfere with those.

I can't get my regression test to work, since I can't figure out how to import the package properly. I am pretty certain that I am overseeing something obvious.

My folderstructure looks as follows:

+- ascripts
|     +-- dependencies.as
|
+- root.fla
+- initialize.as
+- regressiontest.as 

root.fla is my one and only fla file. It just contains:

stop();
include "initialize.as" // Let's go outside!

initialize.as contains all the magic. I am using this external file so I don't have to use the Flash IDE (since it is the worst IDE for coding). In there I have this:

// ... 
import fl.controls.ComboBox;
include "ascripts/dependencies.as"


var t = new regressiontest.TestRunner(); // 1.


// ... 

At 1. I am trying to instantiate my regression test class. It can be found in the file regressiontest.as and looks like this:

package regressiontest {
    public class TestRunner {
        public function TestRunner() {
            trace('Hello');
            // Actual Test Code Here ...
        }
    }
}

So now when I go to flash and debug the movie using Strg+Shift+Enter, I get the following error messages. I tried every way I could think of, so here is an overview of what I achieved so far:

var t = new TestRunner();

Message: 1180: Call to a possibly undefined method TestRunner.

var t = new regressiontest.TestRunner();

Messages:

root.as: 1120: Access of undefined property regressiontest.

regressiontest.as: 5001: The name of package 'regressiontest' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. folder\regressiontest.as

regressiontest.as: 5008: The name of definition 'TestRunner' does not reflect the location of this file. Please change the definition's name inside this file, or rename the file. folder\regressiontest.as

import regressiontest.TestRunner;
var t = new TestRunner();

root.as, Line 19: 1172: Definition regressiontest:TestRunner could not be found.

root.as, Line 20: 1180: Call to a possibly undefined method TestRunner.

What is most confusing to me is that Flash appears to be picking up the class definition in regressiontest.as somehow. When I put an obvious error, such as

public function TestRunner() {
    shoelace('Hello');
}

and use this to instantiate an object of the class:

var t:TestRunner = new regressiontest.TestRunner();

then I get the Message:

regressiontest.as: 1180: Call to a possibly undefined method shoelace.

One might think now that the instantiation causes the problem. But when I set the code from shoelace to trace and leave the instantiation I get the following messages:

Messages Scene 1, Layer 'AS', Frame 1: 1046: Type was not found or was not a compile-time constant: TestRunner.

root.as: 1120: Access of undefined property regressiontest.

regressiontest.as: 5001: The name of package 'regressiontest' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. folder\regressiontest.as

regressiontest.as: 5008: The name of definition 'TestRunner' does not reflect the location of this file. Please change the definition's name inside this file, or rename the file. folder\regressiontest.as

I tried renaming the file within the package, I tried renaming the package, I tried importing with import regressiontest.*; and so on. What am I missing?

  • What do I need to set my filename to? Does it need to match the PACKAGE NAME or the CLASS NAME?
  • Am I missing some crazy camel case rule?
  • Is there a maximum length to package names or something crazy like that?
  • Did I forget to configure flash or the FLA file correctly?
  • Am I missing some magic keyword?
  • Might there be sideeffects from the includes or imports at the beginning of my script?

I can reproduce these steps and I can provide the package via github.

Thank you in advance, with clueless greetings from Heidelberg, Germany

Johannes


Solution

  • As I see it, TestRunner is the class and regressiontest is the package, so you need import the class.

    import regressiontest.TestRunner;
    var t:TestRunner = TestRunner();
    

    Also, you must do this changes.

    1. The filename must be exactly the same of the class, replace regressiontest.as by TestRunner.as
    2. Create a folder for the package and call it regressiontest, put inside TestRunner.as.