getDefinitionByName "Variable Not defined" workaround - actionscript-3

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)

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.

ActionScript Library Project vs. Flex Library Project

I've got couple of issues from the nature of inconsistency between FlexLib Project and AS3 Lib Project in Flash Builder 4.7, AIR SDK 15, 16 and 17, Flex SDK 4.6.
Common thing for these is that FlexLib does not allow (syntax error highlighted) to build/compile pieces of code that are allowed in regular AS3Lib Project.
Please note that examples bellow are simplified, and there are real life use cases even if it's against good practices.
Internal classes above package
internal class Before
{
public function Before(){}
}
package
{
public class Main
{
public function Main()
{
}
}
}
In Flex Library Project this code causes:
1083: Syntax error: package is unexpected.
In regular ActionScript Library project it works perfectly fine, without a single warning.
Array key type greediness
var array:Array = [Boolean, Number, XML];
for(var c:Class in array)
{
if(c is Object) { trace('test') }
}
In Flex Library Project this code causes:
1067: Implicit coercion of a value of type String to an unrelated type
Class.
In regular ActionScript Library project it works perfectly fine, without a single warning.
Constant defined class
public static const FileClass:Class = String;
public function main():void
{
if('test' is Vector.<FileClass>)
{
trace('what?');
}
}
In Flex Library Project this code causes:
1120: Access of undefined property FileClass.
In regular ActionScript Library project it works perfectly fine, without a single warning.
I'd be very thankful if someone could say a word why is this happening or could give me a clue where to look for solution.
According to this, there are two different compilers involved:
Use Legacy Compiler
For ActionScript projects, Flash Builder uses the ActionScript Compiler (ASC) by default. If you are using Adobe Flex SDK 4.6 or an earlier version of the Flex SDK, select Use Legacy Compiler to use the older compiler.
I guess that explains the difference.
The following is an attempt to work around the problem.
I'm not too much into library projects.
From what I found in resources (the link above), these projects result in a .swc file.
I'm not too much into flex either.
Flex is "just" a framework written in actionscript.
Whether your library is an actionscript library or a flex library is not really a choice of the user, but what your code does.
If your library includes some flex components, I'd say it's a flex library project.
But if it is plain old actionscript, it is an actionscript library.
Let's say your library is an actionscript library.
You compile your library into an .swc file and be done with it.
Your are the one doing that compilation step, not the user of your library. I don't think it's their concern if they could perform this compilation.
What actually concerns them is whether their project that includes your library (the .swc file) compiles. And I guess that this will be the case, because the .swc will be used, not compiled.
After all, there's no choice to be made, if it is an actionscript library, because every flex project is an actionscript project. (but every actionscript project is a flex project)
Build your library project (whatever compiler works) and see if you can use the resulting .swc file in both an actionscript and a flex project.

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

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

Access of undefined property CONFIG::

I am trying to build a Flex project with flash builder 4.6. This project should be fully functional because it has been built before, however I am getting a lot of build errors involving "CONFIG"
The error:
"Access of undefined property LOGGING."
CONFIG::LOGGING
{
import org.osmf.logging.Logger;
}
To be honest I am a ActionScript noob, so I am not sure what to call this snip of code. Although it looks like a namespace or a struct I suspect its a configuration option. How so I define this property LOGGING? Why would it be missing?
It sounds like you're missing a compiler argument that adds conditional compilation. Check out the docs.
Basically, you'll need to add something like this:
-define=CONFIG::LOGGING,true
to your compiler string.