Extending MXML component, Ambiguous Reference - actionscript-3

I'm having some trouble extending classes in MXML, I will attempt to explain here, but I have also uploaded a Sample Flash Builder Project.
Consider that I have 2 classes:
game.implementation.base.view.MainView
game.implementation.ipad.view.MainView
note that they have slightly different package names (one is for ipad).
The idea is that the ipad package's classes will extend the classes of the base package.
Doing as described above produces an error:
Ambiguous reference to MainView. [Generated code (use -keep to save):
Path:
D:\FlexTests\Tests\bin-debug\generated\game\implementation\ipad\view\MainView-generated.as,
Line: 95, Column: 62]
I have reviewed the generated code, the offending function is:
_watcherSetupUtil.setup(this,
function(propertyName:String):* { return target[propertyName]; },
function(propertyName:String):* { return /** HERE **/ MainView[propertyName]; },
bindings,
watchers);
I have narrowed the problem down, I think it is caused by:
Extending class having the same name
Extending class using bindings in the MXML
Is there a way to fix this without doing either of the above?
I would prefer not to rename the classes, and obviously removing the bindings is not an option.

Yes it's a bug in the compiler, I found an old bug issue and cloned it:
FLEX-33580: CLONE - Ambiguous reference when using data binding in inherited class with the same name as base class in a different package
This only occurs when the:
(a) Extending class has the same name as base class, but is in a different package .
(b) Extending class makes use of data binding.
The workaround is to rename one of the classes.

Related

AS3 package issue

Really want to refactor and re-architect my project, it's become basically an 11k line monobloc that desperately needs to be split into multiple classes (and class files) inside a single package.
Yes I know I should have figured all this out when I started, but this is play not work and I was brand new to AS3 when I started. And I've kept building and building and it all works, it's just become very hard to manage.
My immediate goal is to define a package and then start breaking out function groups from the current main class into subclasses that extend the base. But I'm having a problem with the first step - defining the package.
I'm getting:
C:\Users\Vossie\Documents\Fex Line of Battle Project\trunk\line_of_battle\LOB_Core.as, Line 1, Column 1 5001: The name of package 'line_of_battle' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. C:\Users\Vossie\Documents\Fex Line of Battle Project\trunk\line_of_battle\LOB_Core.as
So I've checked:
package line_of_battle {
public class LOB_Core extends flash.display.MovieClip {
Filename is LOB_Core.as.
Path:
I explicitly added it to the class search path:
So:
Name of package agrees with name of folder (I actually pasted it from folder to .as file)
Package file is within that folder.
Class search path includes that folder
Shouldn't matter for this but filename and public class name match
I've searched stack overflow and one similar case involved a text case mismatch that I don't see here. One other related question the guy's question turned into just how to make classes and name the files correctly.
According to the documentation I read, this should work fine. Can someone tell me what I am missing?
Edit - This is the code that's triggering the error, LOB_Core.as:1102 -
var test:LOB_Scenario_Data = new LOB_Scenario_Data();
And the class that is calling:
package line_of_battle {
import line_of_battle.LOB_Core.*;
public class LOB_Scenario_Data extends LOB_Core {
public function LOB_Scenario_Data() {
// constructor code
trace("BIG MONKEYS");
}
}
}

Checkstyle check for duplicate classes

The project I am on is having horrible problems with class collisions in the classpath and developers reusing class names. For example, we have 16, yes 16 interfaces called Constants in this bloody thing and its causing all kinds of problems.
I want to implement a checkstyle check that will search for various forms of class duplication. here's the class
import java.io.File;
import java.util.List;
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.wps.codetools.common.classpath.ClassScanner;
import com.wps.codetools.common.classpath.criteria.ClassNameCriteria;
import com.wps.codetools.common.classpath.locator.ClasspathClassLocator;
/**
* This codestyle check is designed to scan the project for duplicate class names
* This is being done because it is common that if a class name matches a class
* name that is in a library, the two can be confused. Its in my best practice that
* the class names should be unique to the project.
*
*
*/
public class DuplicateClassNames extends AbstractFileSetCheck {
private int fileCount;
#Override
public void beginProcessing(String aCharset) {
super.beginProcessing(aCharset);
// reset the file count
this.fileCount = 0;
}
#Override
public void processFiltered(File file, List<String> aLines) {
this.fileCount++;
System.out.println(file.getPath());
ClassScanner scanner = new ClassScanner();
scanner.addClassCriteria(new ClassNameCriteria(file.getPath()));
scanner.addClassLocater(new ClasspathClassLocator());
List<Class<?>> classes = scanner.findClasses();
if (classes.size() > 0) {
// log the message
log(0, "wps.duplicate.class.name", classes.size(), classes);
// you can call log() multiple times to flag multiple
// errors in the same file
}
}
}
Ok, so the ClassScanner opens up the classpath of the current JVM and searches it with various criteria. This particular one is a class name. It can go into the source folders, and most importantly it can go into the libraries contained in the classpath and search the *.class files within the jar using ASM. If it finds copies based on the criteria objects that are presented, it returns an array of the files. This still needs some massaging before mainstream but im on a time budget here so quick and dirty it goes.
My problem is understanding the input parameters for the check itself. I copied from the example, but it looks like CheckStyles is giving me a basic IO file object for the source file itself, and the contents of the source file in a string array.
Do I have to run this array thru another processor before I can get the fully qualified class name?
This is more difficult to do right than one might think, mostly because Java supports all kinds of nesting, like static classes defined within an interface, anonymous inner classes, and so on. Also, you are extending AbstractFileSetCheck, which is not a TreeWalker module, so you don't get an AST. If you want an AST, extend Check instead.
Since "quick and dirty" is an option for you, you could simply deduce the class name from the file name: Determine the canonical path, remove common directories from the beginning of the String, replace slashes with dots, cut off the file extension, and you are more or less there. (Without supporting inner classes etc. of course.)
A better solution might be to extend Check and register for PACKAGE_DEF, CLASS_DEF, ANNOTATION_DEF, ENUM_DEF, and INTERFACE_DEF. In your check, you maintain a stack of IDENTs found at these locations, which gives you all fully qualified class names in the .java file. (If you want anonymous classes, too, also register for LITERAL_NEW. I believe in your case you don't want those.)
The latter solution would not work well in an IDE like Eclipse, because the Check lifecycle is too short, and you would keep losing the list of fully qualified class names. It will work in a continuous integration system or other form of external run, though. It is important that the static reference to the class list that you're maintaining is retained between check runs. If you need Eclipse support, you would have to add something to your Eclipse plugin that can keep the list (and also the list from previous full builds, persisted somewhere).

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

netbeans: API Versioning tab, public packages org.demo.textfilter not automatically imported

following the tutorial at
http://platform.netbeans.org/tutorials/nbm-quick-start.html#lookup
"Right-click the "TextFilter" module, choose Properties, and use the "API Versioning" tab so specify that the package containing the interface should be available throughout the application: " (org.demo.textfilter is set to public)
the problem is, this public package is not automatically imported by another class in another module with dependency on the TextFilter module. Whenever the dependencies are added, shouldn't the dependent classes/modules automatically import the dependencies ?
Your question is a bit hard to interpret, so I will tell you what I think you are asking and then provide an answer....
I assume that you have a couple netbeans module projects: TextFilter and MyModule.
Initially, MyModule depends on TextFilter.
There is a third module, let's call it Filter... that has a public, exported class org.filter.BaseClass.
You have made TextFilter dependent on Filter, so you can use the org.filter.BaseClass in the TextFilter module.
You are now attempting to use org.filter.BaseClass in MyModule and that is not working.
Module dependency defines the visibility of classes. That visibility does not span modules.
If you want MyModule to be able to use org.filter.BaseClass, you need to explicitly define the dependency between the module Filter and MyModule.