Error: Call to a possibly undefined method startTest - actionscript-3

I'm new to flash development. I got an actionscript (3.0) code to work with, which I'm trying to compile using mxmlc.exe
import flash.display.*;
startTest();
function startTest() {
// Create objects to other classes to start display
}
When I compile it with the below command
mxmlc.exe Main.mxml
Where the above .as file is included, I keep getting the following error
Error: Call to a possibly undefined method startTest.
There in no class or package is defined in the .as file.
Please provide some inputs here.

Related

ExternalInterface - There is no method with the name

I know very little about Flash, but I need to be able to call a JS function from inside a ActionScript file.
When I enter the line:
ExternalInterface.call("alert", "test");
I get the error:
There is no method with the name 'ExternalInterface'.
In the tutorials it seems I have to include the namespace:
import flash.external.ExternalInterface;
but I don't know where to put that?
I place it outside the class that extends a mediaclip and it does nothing.
How do I include that reference so that the ExternalInterface method is recognized?
What's odd is that intellisense works and allows me to type it in and gives me the overloaded methods, so it knows what I'm trying to say, it just doesn't work when I try to compile it.
You could also try access the class doing this:
flash.external.ExternalInterface.call("alert", "test");
That way you don't have to import the package with the class.

Problems with compiling multiple AS3 packages w/ant and mxmlc

I'm trying to extend the BigBlueButton client with some proprietary classes. Specifically the phone module, where I added a file with my own code. When I write my own package name (org.mydomain.module.test ...) within the file, the compiler fails because it can't find my class from the mxml file. But when I use the original package name (org.bigbluebutton.module.phone ...) it compiles fine. Obviously when I use a different package name, the file is not included in the compilation. How can I change this?
This fails:package org.mydomain.module.test
{
public class MyTestClass
{
// code here
}
}
But this works:package org.bigbluebutton.modules.phone.test
{
public class MyTestClass
{
// code here
}
}
FYI: BigBlueButton uses ant to compile the client.
You didn't say where you put the files on disk, the package name should match the file's path in your project. Is that the case in both examples?
So when the package name is: org.mydomain.module.test
The class file should be saved in the path:
my_project_path/src/org/mydomain/module/test

AS3 Access of undefined property error

I have code that reads a JSON file to import the information about a level in a game I'm making. The code was running and compiling fine until suddenly every time I tried to build, FlashDevelop started erroring "build failed" without actually giving an error.
I ran the code through the mxmlc compiler, to give me an error message, and it returned an error saying "Error: access of undefined property JSON" in line:
var level:Object = JSON.decode(json);
This is confusing because the JSON library is clearly included at the top of the file, "import com.adobe.serialization.json.JSON;", and this error started occurring completely on it's own, which is odd...
package
{
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.ByteArray;
import net.flashpunk.Entity;
import com.adobe.serialization.json.JSON;
public class LevelParser
{
public static function GetLevelByID(ID:int, source:Class):Level
{
// Store new entity
var populated:Vector.<Entity> = new Vector.<Entity>();
// Parse file into string
var bytes:ByteArray = new source();
var json:String = bytes.readUTFBytes(bytes.length);
var level:Object = JSON.decode(json);
// Find correct level
...
EDIT: Strangely if I comment out the line to call it, and this function, the code compiled fine in mxmlc, but in Flashdevelop is says "Build Failed" with no error
This is actually a reference error.
As of AS3 SDK 4.5, JSON became a native class within the SDK. In previous versions, you would have to download the adobe serialize classes to access JSON - which may be your issue.
When using the mxmlc, it will compile with all the included libraries specified in your sdk flex-config.xml. In FlashDevelop, it will only use the classes you include.
Solution: add the adobe serialize class to your project

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
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.
The filename must be exactly the same of the class, replace regressiontest.as by TestRunner.as
Create a folder for the package and call it regressiontest, put inside TestRunner.as.

I get error when importing fxg into flex 4.6 project

I made an fxg file using Inkscape and the fxg plugin. It is called BugattiVeyron.fxg
I also created AS3 project using flex sdk 4.6 and FlashDevelop 4 and import this file using the import statement like this
import BugattiVeyron;
and instantiate it like this
private var bugatti:BugattiVeyron = new BugattiVeyron ();
Using the build button in FD4 does not give any errors, but when i run it I get this error although when I dismiss all the errors the file is beign imported well and I can add events to it.
the error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::updateCallbacks()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7345]
at mx.core::UIComponent/set nestLevel()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:4189]
at spark.core::SpriteVisualElement/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2247]
at spark.core::SpriteVisualElement/addChild()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:2211]
at resources::BugattiVeyron_Text_2126220941/createText()
at resources::BugattiVeyron_Text_2126220941()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at mx.core::FlexSprite()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\FlexSprite.as:61]
at spark.core::SpriteVisualElement()[E:\dev\4.y\frameworks\projects\spark\src\spark\core\SpriteVisualElement.as:88]
at resources::BugattiVeyron()[resources\BugattiVeyron-generated.as:10]
so i get this error but the file is imported after I dismiss the errors.
what could be the problem, any idea?
I struggled with this issue myself and finally figured out how to get it working. There are two ways.
Your FXG file needs to be in the same directory as your Main.as in order to call it like this:
import BugattiVeyron;
But or course if you have your image assets in another folder you will have to set a class path in your project in order to reference the FXG file. Obviously we can't access the FXG file in another directory like this:
import ../lib/BugattiVeyron
If you right click on your project in FlashDevelop and click on Properties from the context menu you will be able to add your directory of choice as a classpath in order to access your FXG file. In my case I added lib as a classpath for the project. This enabled me to import my asset like you previously tried doing.
import BugattiVeyron;
public class Main extends Sprite {
var bugatti:BugattiVeyron = new BugattiVeyron();
..some code here...
}
Hope this helps, I struggled for a week trying to figure this out.
I ran into the same problem, specifically when trying to instantiate an FXG that contained text (a <RichText> element) from an AS3-only project (no MXML) in FlashDevelop. I was able to import and use other FXG files that didn't contain RichText without any trouble.
I'm a little hazy on the exact details, but it seems that the error occurs as a consequence of the call to createText() (resources::BugattiVeyron_Text_2126220941/createText() in your case) because the Flex library isn't initialized for a pure AS3 application. The simplest solution is to define the application in MXML rather than AS3, i.e.
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:bv="*"
>
<bv:BugattiVeyron/>
</s:Application>
instead of
import BugattiVeyron;
public class Main extends Sprite {
var bugatti:BugattiVeyron = new BugattiVeyron();
}
(More on this in a related question: [Possible to use Flex Framework/Components without using MXML?. Look for the "necessary updates for Flex 4" section.)
Alternatively, if you don't want the runtime overhead of the Flex libraries, you can edit your FXG to convert the text to paths. This should work with AS3-only projects, but I wouldn't be too surprised if there were other FXG features that ran into similar problems.