Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex Metadata Compiler Extension in FlashDevelop tutorial

I've been googling around for the past 2 hours looking for some simple instructions on how to add my own custom metadata tag in as3 with no success. I'm starting to think that I'm probably not searching for the correct terms.

The Problem

Ultimately, what I want to do is add a custom metadata on a function that takes a function as a parameter and makes sure that the given function has the correct parameters.

I.e. I have the following function:

public function testCallback(callback:Function):void
{
    callback("test");
}

and I want to get a compiler error when I call it like this:

public function doNothing():void
{
    // doing nothing
}

public function someRandomFunction():void
    // ...
    testCallback(doNothing);
}

The way I'm thinking of doing this is by having this metadata:

[Callback(paramName="callback",callbackParams="string")]
public function testCallback(callback:Function):void
{
    callback("test");
}

The extension would run during compilation and, if the function passed does not contain the correct parameters, a compile-time error will be thrown. I THINK by using flex2.compiler.util.ThreadLocalToolkit.logError(path, line, errorMessage); I can accomplish this.

The Search

I've been googling for a couple of hours now and couldn't find a simple tutorial that could get me started. I found some SDK bug reports (SDK-18718, SDK-26041), an unfinished forum post, a tutorial (?) on how to add a custom metadata in FlexBuilder (I'm using FlashDevelop), a not-so-useful answer in StackOverflow and many many more dead ends.

The Help

So far, as far as I could understand, I will use Java to create the extension and then, using a compiler command, I'll add it into my project. However, I don't know what do I need to get started.

My two main questions are:
A) What do I need to create the extension in Java? (do I need Flex Builder? Eclipse? what libraries do I need in my classpath?)
B) Once I have compiled this into something (a swc?), how do I include this in FlashDevelop in my AS3 Project?

Thanks in advance!

Update

I've been able to create a Java project in eclipse, add the Flex libraries, implement the IMxmlcExtension interface and compile the project into a jar with the correct MANIFEST file. Unfortunately, adding the extra -extension=MyTest.jar in FlashDevelop, did nothing.

In case it is useful, the resulting command line for the compiler was

mxmlc -load-config+=obj\MyProject.xml -debug=true -incremental=true -swf-version=10 -extension=flex_test.jar -o obj\MyProject634846490611881374

Update 2

Timofei Davydik helped me narrow down the problem. It seems that FlashDevelop is the main problem. Creating an extension and compiling it in command line works. I started a thread in FlashDeveloper's forums. In case you're interested, the thread is: -extension compiler option

Update 3

Pilippe is correct, it seems that the problem comes from the fact that FlashDevelop uses Flex Compiler SHell (fcsh). I am now looking into how can I switch compilers.

like image 201
pek Avatar asked Nov 04 '22 15:11

pek


1 Answers

Really interesting question. I've done some research. Yes, we can write mxmlc extensions and add some custom functionality. But processing custom metadata is really complicated, and much time is needed debug and explore flex compiler sources. I've created a post in my blog about extensions, you can check it:

http://tim-davydik.blogspot.com/2012/09/flex-compiler-mxmlc-extensions-forcing.html

like image 84
Timofei Davydik Avatar answered Nov 09 '22 07:11

Timofei Davydik