What does Application.application mean? - actionscript-3

I'm following a block of sample code that contains the line:
Application.application.addChild(myPrintData);
I am placing the code into a custom class (it's a Canvas) and I get an error message when I attempt to use Application.application....
The error is: -Access of undefined property Application
What does it mean and how can I get around it?

You are probably missing the import statement in your custom class.
import mx.core.Application;
Application is a layer of abstraction with a static object application which is the current application instance.
See note below from Reboog711. Thanks for the correction.

Related

import issue of "serialization.json.JSON" class in actionscript:

I'm working on a project using actionscript and Flex. For some reason I have a problem importing the com.adobe.serialization.json.JSON class.
When I'm working only with the FlexSDK files and try to use it I'm getting
the following error:
Error:(142, 70) [..]: Error code: 1120: Access of undefined property
JSON.
And of course IntelliJ marks this file and the import in red.
On the other hand when I import the corelib.swc that includes this file I get the following error:
Error:[..]: Can not resolve a multiname reference unambiguously. JSON
(from /Volumes/backup/FlexSDK/frameworks/libs/air/airglobal.swc(JSON,
Walker)) and com.adobe.serialization.json:JSON (from
/Volumes/backup/.../libs/corelib.swc(com.adobe.serialization.json:JSON))
are available.
What is going on here? How can I solve this?
JSON is a top level class available in all the scopes since FP11. Trying to import any class with name JSON will result in an error. If (for some reason) you really do not want to use the already available JSON class and instead import a custom one you'll have to rename it.
Using Intellij, the best you can do is use the JSON class from the current SDK that you have, it has the methods parse() and stringify(). those two methods do the same as the corelib methods for the json.
In case you wanted to use the com.adobe.serialization.json.JSON it will enter in conflict with the one declared in the SDK.
Hope the information is useful

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.

Adobe Flex compiler include classes

I'm trying to create and instance of an object by reference the class object of the class using
getDefinitionByName()
the problem is that if I don't create at least one instance of the class before when try to use getDefinitionByName() it say
ReferenceError: Error #1065: Variable XXXXXX is not defined.
how can I include the class in the binary without using and instance first??, also I had tried to juts leave in the import but still don't include the class, it could be a compiler param I can pass??
I'm using Flex SDK 4.6 thanks!!!!!
As described in the documentation:
-includes class Links one or more classes to the resulting application SWF file, whether or not those classes are required at compile time
There is a bunch of compiler options which allow you to include classes, but they aren't very scalable / require some manual labour. For example, there's -includes option, but you must know what symbols to include. There's -include-libraries, but again, you'd have to compile a SWC library with the classes you need. -include-namespace - you'd need to write the namespace definition, listing all classes that you want to include.
Since I imagine that the task in the end will get automated one way or another, it would make more sense to just generate an AS file of the following format:
package your.app {
import fully.qualified.class.Name;Name; // it is enough to just mention it
. . .
}
And then include only this this class.
Well I think I found the solution, just add to the compiler the argument -includes like thised
-includes com.example.Myclass
that will include the class object in the binary even though u haven't used and after tried to load it with getDefinitionByName()
hopes this help to someone else, also here is a complete list of arguments for the compiler
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7a92.html

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.

Global Error Handler for Flash Player 10.1 not working

Trying to implement the new FP 10.1 Global error handler into my projects but no matter what I do any uncaught error will still show up the Exception window (both in debug and release versions of the SWF). All I want to do is to prevent these popups but instead send a message to my logger. Here's my code ...
EDIT: I simplified the code now. Could somebody do me a favor and test the following class and see if it's works for him? Because it's doesn't for me! ...
package
{
import flash.display.Sprite;
import flash.events.UncaughtErrorEvent;
public class GlobalErrorHandlerTest extends Sprite
{
public function GlobalErrorHandlerTest()
{
stage.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
throw new Error();
}
private function onUncaughtError(e:UncaughtErrorEvent):void
{
var message:String;
if (e.error["message"])
{
message = e.error["message"];
}
else if (e.error["text"])
{
message = e.error["text"];
}
else
{
message = e.error["toString"]();
}
trace("Uncaught Error: " + e.text);
}
}
}
I had the same issue as above - I was referencing stage.loadInfo, believing that as that references the stage, it would capture all uncaught errors. However, that doesn't work, you have to actually follow grapefukt's suggestion verbatim: On the actual base display object, place the code
loaderInfo.uncaughtErrorEvents.add...
When you try to place onto stage.loaderInfo or frame.loaderInfo, it has no effect.
In my case, I had to place it in the class that extended the base display object. Very Odd.
The docs say that:
The UncaughtErrorEvents object that dispatches the event is associated with either a LoaderInfo object or a Loader object.
Thus you must listen to the loaderInfo's uncaughtErrorEvents property of your topmost display object:
loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);
UPDATE: I think I may know why you think this isn't working. I made the mistake of testing inside the debugger. When the debugger stopped on the runtime errors I assumed that this proved my uncaughtErrorHandler function was not working. In fact, this was in error. It's just a quirk of the debugger. The debugger will still stop as if it is an unhandled error or exception, but if you press Run again you'll see it DOES execute the error handling code. See my thread Flex 4.0/4.5 global error handling for more info.
Original response:
I am looking for this same info. None of the examples in the API doc nor various blogs on the subject work for me. I've tried just loaderInfo, stage.loaderInfo, systemManager.loaderInfo... It makes no difference. I even tried all of them in a single test case! The addEventListener are being set but the uncaught errors are not firing the uncaughtErrorHandler. Argh. I have wasted far too much time on this! I've reduced it to a very simple program much like above except with all the code in the main mxml file.
How about this: can someone post a Global Error Handling example that DOES work? I'm using Flex SDK 4.1 (I've also tried with 4.5), targeting FP 10.1 (or 10.2 for 4.5), in a mx:Application-based mxml Flex project.
My thread: Flex 4.0/4.5 global error handling
You must set up the listener not to a specific view, but to the main stage object, as it's at the top of the display list (thus picking up any exception of any of its children).