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

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

Related

How to have class loaded without using "use" but call it as if I used it

I have studied these 2 sources, but none of those works for me.
http://www.yiiframework.com/doc-2.0/guide-concept-autoloading.html
Yii2 - How do I AutoLoad a custom class?
I have created custom helper class which I want to include in every model, controller and view in my application. I am using Yii2 advanced app version 2.0.11, IDE I am using is PHPStorm
QUESTION:
What I want to achieve is to not use use keyword at the beggining of every class but still be able to simply call AppHelper::myMethod() in models, controllers and views.
How is that possible?
Closest I got it working was using this solution https://stackoverflow.com/a/35160997/5395463
All other solutions did not work for me. I am getting errors like:
PHP Fatal Error – yii\base\ErrorException
Class 'frontend\controllers\AppHelper' not found
when I simply dont include use commons\commands\AppHelper;
or when not using namespace as they suggest there with other settings:
Fatal error: Uncaught exception 'yii\base\UnknownClassException'
with message 'Unable to find 'common\commands\AppHelper'
in file: C:\xampp\htdocs\domain.com\web\common/commands/AppHelper.php.
Namespace missing?' in ...
SOLUTION:
Thanks for your responses, I got it working finaly. https://stackoverflow.com/a/42330631/5395463 solution works best for me.
So I removed namespace from that class, but left it in common\commands folder, added require to frontend/web/index.php and backend/web/index.php files (not sure if I should add it to yii file in root too, I didnt, so far it is working good anyways), and changed calls of class from AppHelper::myMethod() to \AppHelper::myMethod() looks like eveything is working now.
In Yii2 You can use an explicit way adding \ to full namespaced name
\frontend\controllers\AppHelper
so you can sue your method
\frontend\controllers\AppHelper::yourMethod();
Solution for not lazy coders:
create component with your class so you can use it like \Yii::$app->my_component
if even this is too much and your IDE is better than Windows Notepad prepare macro that will print this for you
Solution for lazy coders:
Save your class in single PHP file without namespace.
Modify you entry script to include this class - i.e. for Basic Project Template it's /web/index.php; add there
require(__DIR__ . '/path/to/MyClass.php');
For Advanced Project Template modify it properly.
Now you can use your class by calling it like \MyClass (yes, \ is required and yes, your IDE probably will modify it anyway to MyClass with use MyClass; added at the beginning.

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

What does Application.application mean?

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.

Error: Access of undefined property JSON ... but it IS there

I am developing a Flash application (Flash Player 11 as target platform) that uses the AS3 Facebook API, which in turn uses as3corelib JSON functionality. Or at least it should do so.
However, in spite of including the latest version (.93) of the as3corelib.swc, I still get the "Error: Access of undefined property JSON". I also tried including the sources directly, to no avail.
Any ideas what I am doing wrong?
As I said, the *.swc is definitely included. As is the source code (all at the correct path).
Edit:
I have a more specific error message:
Error: Can not resolve a multiname reference unambiguously. JSON (from C:\Coding\FlashDevelop\Tools\flexsdk\frameworks\libs\air\airglobal.swc(JSON, Walker)) and com.adobe.serialization.json:JSON (from C:\flash_test\lib\as3corelib.swc)) are available.
I know that JSON is included in AIR, but I do not target AIR, so why does it try include the airglobal.swc?
Your problem is that Flash Player 11 and onwards has native JSON support, so the JSON class you are including is likely colliding with the one from as3corelib. Hence the ambiguity problem.
Try removing as3corelib entirely and see what happens.
Specify the full path to the class. Example, code:
...
var jsonData:Object = JSON.decode(loader.data);
...
will be
...
var jsonData:Object = com.adobe.serialization.json.JSON.decode(loader.data);
...