简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM