2
votes

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.

1
Extending classes that use bindings in MXML should cause no issue. However, two classes with the same name can cause all sorts of issues. If I had to guess--and this is just a guess--the ActionScript generated from the MXML is not fully qualifying the class name in some place where the class is referenced; and this is causing the ambiguous reference because it can't tell which class is being referenced. It could be a compiler bug; albeit I bet the use case for this is low. Quick Fix: Change the name of "MainView" to "MainViewIPad" or something similar.JeffryHouser
I noticed something after that previous comment I didn't notice; which is the "MainView" reference in your code snippet. So, I'm sure the problem is the fact that that class name is not fully qualified. Perhaps both classes are referenced/imported in the generated code somehow?JeffryHouser
@Reboog711: Yes it's a bug in the compiler, I found an old bug issue and cloned it: issues.apache.org/jira/browse/FLEX-33580Drahcir
I'm glad you have a answer, even if it isn't a solution. :-)JeffryHouser

1 Answers

1
votes

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.