Adobe Flex compiler include classes - actionscript-3

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

Related

How do I avoid conflicts between haxe Type class and C# Type class?

I am developing Haxe code that I convert in C# and insert into a Unity project.
The conversion works fine and I am able to use the generated class when I import it alone in Unity.
To make it work, I have to bring in Unity the whole generated src folder, including the Type.cs file.
However, when I import the "Post Processing Stack" (a basic Unity extension) I get errors due to name Conflicts. The Type class is also a basic C# class and It is used by the Post Processing scripts.
The haxe-Type takes priority and breaks the compilation:
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,30): error CS1502: The best overloaded method match for `System.Collections.Generic.Dictionary<Type,System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>>.Add(Type, System.Collections.Generic.KeyValuePair<UnityEngine.Rendering.CameraEvent,UnityEngine.Rendering.CommandBuffer>)' has some invalid arguments
Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs(406,34): error CS1503: Argument `#1' cannot convert `System.Type' expression to type `Type'
I don't know if it is possible to solve this issue by playing around with C#/Unity/Mono search paths.
I as wondering wether it is more appropriate to (optionally) wrap all haxe top-level classes into the haxe namespace, or a special haxe-defaultnamespace, or prefix them for example to class HType.
Name conflicts for this basic types are likely to emerge in many other contexts, not only in Unity.
I found the solution in the Haxe documentation for C#:
https://github.com/HaxeFoundation/HaxeManual/wiki/Haxe-C%23
-D no-root generate package-less haxe types in the haxe.root namespace to avoid conflicts with other types in the root namespace
This way, all the classes that were at global level will be generated under namespace haxe.root.

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.

getDefinitionByName "Variable Not defined" workaround

Ok so I have game data parser that creates a game out of data file basically, it is using extensively getDefinitionByName which has one problem if the class is not loading somewhere else it throw variable not defined error information=ReferenceError: Error #1065: Variable {MyClass} is not defined. to workaround it I am using a class that holds all the list of components and instantiate it to make these classes available to the compiler.
Ok the question part is there any more efficient way to do that or playing with compiler argument or something ?
Is there something like export in first frame in flash professional as a compiler argument ?
I think what you want is to have a library project with all those "callable" classes, and then reference that library project in your game.
In flash builder, for a library project, you can check which classes are compiled (and so available to getDefinitionByName). (info here)

What is __AS3__?

Sometimes in debug mode with Flash Builder, I see something like
__AS3__.vec.Vector.<Object> (#909e219)
but when I try to store this variable in another as3 variable, Flash duplicate this variable. Concretly, I'm trying to exclude some values on dragInitiator.selectedItems property before adding them to a List but when I use splice method on it, values aren't deleted from this vector.
So how can I acces variable with __AS3__ namespace please ?
According to a Tamarin developer:
The namespace "__AS3__.vec" is an artifact of a time when we did not have good API
versioning and could not introduce new top-level names without the risk of breaking
existing code. Today we would probably have made "Vector" public & versioned.
Source: http://hg.mozilla.org/tamarin-redux/rev/817f3e019ba2#l2.30
In other words, __AS3__ is the package where are defined Flash internal classes into Tamarin VM.
To access such variables, you don't need to specify the namespace. You only have to use the FQN declared in playerglobals.swc.

how to force compiler compile all classes in my project?

im using Adobe® Flash® Builder™ 4.6,the problem also exist in previous versions.
for some reason ,i am using
cls = applicationDomain.getDefinition(name) as Class;
to get the object's constructor and then create the instance of my modules class.thus make compile ignore my module classes ,because they are not related from my main class.how to force else classes also compiled into my swf or swc file? i didn't find where i can adjust my compile option.
by now i use this way to solve my problem,at the very beginning of the program entry.
if(1+1==3){
//never be run but do make classes merge into swf files.
new MyModule();
}
i have hundreds of modules like this one,i do hope i can find a way to solve this problem permanently
You can try with this
package
{
public class IncludeClasses
{
import com.abc.db.Database;Database;
import com.abc.logs.RemoteLogTarget; RemoteLogTarget;
import com.abc.logs.LocalLogTarget; LocalLogTarget;
import com.abc.exception.GlobalExceptionHandler; GlobalExceptionHandler;
import com.abc.utils.NetConnectionMonitor;NetConnectionMonitor;
}
}
You need to use the class to get it to compile in the swf.
Not the best method but
private var someVar:someClass;
Using the "new" keyword will cause the run-time to allocate memory for the object so you don't want to use that.
This whole loading modules and compiling classes has a code smell to it.
You would be better off having your classes in the modules implement an interface.
You need at least one strict reference to your class to appear within the project. I use a static variable of type Array to stuff all of the classes I need, and never really reference that array, if I can.
private static var dummy:Array=[OneClass, AnotherClass, Class01, Etc];
You can also do this by setting your compiler flag.
About the application compiler options
See:
include-libraries library [...]
Include only classes that are inheritance dependencies of classes that
are included with the include-classes compiler option.
The default value is false.
This is an advanced option. You might use this compiler option if you
are creating a custom RSL and want to externalize as many classes as
possible. For example:
compc -include-classes mx.collections.ListCollectionView
-include-inheritance-dependencies-only=true
-source-path . -output lcv2 -directory