开发者

Can I make my Flex entry-point MXML subclass a custom AS3 class

With MXML components, I've seen a pattern used where you have an AS3 class, then the MXML subclasses it, to have a separation between view/code (anonymized from real code):

package开发者_StackOverflow中文版 com.john
{
 public class MyComponent extends Canvas
 {
  ...
 }
}

<?xml version="1.0" encoding="utf-8"?>
<logic:MyComponent xmlns:logic="com.john.*"
     xmlns:mx="http://www.adobe.com/2006/mxml">
 ...
</logic:MyComponent>

At least I think the MXML component is subclassing the AS3 class?

Anyway is it possible/advised to do this with my main MXML application file, so I can put manager instances and things in the AS3 MyApp class, which is subclassed by Main.MXML?

Real/pseudo code examples are most welcome.


It should be possible, looks like you just need to have your com.john.MyComponent base class extend spark.components.Application or mx.core.Application.

But whether it's advised or not, I don't see the benefits unless you are planning to reuse that base class somehow. If it's a heavy app class or just despise mxml, refactoring out implementation code to a startup command and composing any child views in another container will really lighten the app class. I'd even prefer the app class composing your current MyComponent over converting it to a base application class and extending.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜