Metaliq Components and MTASC

In my last post I briefly mentioned that I would discuss how to tweak the classes that are shipped with the latest version of the Metaliq component set to be compliant with mtasc. The steps that I will take assume that you have purchased a license of the Metaliq component set and have the latest version with the source code. It also assumes you already have mtasc and swfmill setup. If you don’t know what these tools are, or how to set them up, you can go to their respective homepage or find numerous tutorials to help you get up to speed. I actually use FlashDevelop which comes pre setup with both of these tools. The following steps will create a project in FlashDevelop and allow you to start compiling the Metaliq components with mtasc. You should be able to easily translate this to Eclipse or other script editor of choice.

  1. Create a new Library Project and name it “Metaliq”. Make sure to check “Create directory for project”.
  2. In the Project Explorer, open up the properties panel for the project. Under “Test Movie”, change the pulldown option to “New Window”.
  3. Go to the Build tab and delete the Post-Build Command Line text and hit Apply.
  4. Go to the Compiler Options tab and click on IncludePackages. A button with a “…” will appear, click on that. Delete the text in that window and hit OK.
  5. Set UseMain to true.
  6. Set TraceMode to FlashOut. Hit OK and close out of the properties panel.
  7. Find where your Metaliq source code is and copy the “com” folder over to the “classes” directory of your new project. Make sure to copy it and not move it since we will be editing the source.
  8. From the Metaliq source, go to the “flas” directory and copy Button.fla to the “library” directory of your new project.
  9. Open Button.fla in Flash (there should be nothing on the stage). Go to the publish settings and add the following class path: “../classes/” (without the quotes). Save, compile and close.
  10. In the “classes” directory of your project, create a new class named “ButtonTest.as” and add the following code:

    If you look at the class above, you will notice a main method that gets called by mtasc. This main method creates an instance of the ButtonTest class which in turn begins the setup for instantiating a Metaliq component through code. We are using the createClassObject method to instantiate the Button component. The parameters passed are className, instanceName, depth, and an initObject which sets the defaults for the component. Besides the Button class, two other classes are imported in for mtasc. Once you get through with the following steps, remove those imports and the instantiations of those classes to see the error that mtasc throws. It will clearly ask you to force compilation of those classes. The easiest way to do that is by adding in the import statement for each class and then creating a reference to the class by instantiating it. I immediately delete the instance so it doesn’t take up memory.

  11. In FlashDevelop’s Project Explorer, right-click on ButtonTest.as and select “Always Compile”. And right-click on Button.swf and select “Add to Library”.

These previous steps are the basis for setting up a project in FlashDevelop to compile with mtasc and swfmill. The next steps will be getting the Metaliq classes to compile with mtasc.

  1. Hit F5 (Test Movie). You should see an error pop up. Double click on the error to bring up the class that is causing the error.
  2. The error is “unknown variable” in FocusRect.as. If you look in the constructor, there is an onEnterFrame function. Within this function, a call to the draw method is made. The simplest way to fix this is to add “this.” in front of “draw()” to scope the method properly.
  3. Hit F5 again and then do the same for the next error.
  4. The next error is “return type cannot be Void”. If you double click on this error, it will open up UIObject to around line 90 within the glicInit method. If you notice, the return type for glicInit is Boolean but the first line returns nothing. mtasc doesn’t like this. To fix it, change if (initted) to if (!initted) , delete the return and put the rest of the method within the brackets.
  5. Your next error will go back to “unknown variable”. You know how to fix these.
  6. Another error you will get is “Object should be MovieClip”. This is an easy one to fix. Wrap the object that is causing the error in MovieClip() to typecast it.
  7. The next error is “Object should be String”. Just add String() around the offending objects.
  8. The next error is “unknown variable m”. If you look above the error, you will see that m gets declared within an if statement. To fix the error, declare the m above the if statement and set m in the if statement.
  9. The next time you hit F5, mtasc should finally compile nicely. The button probably will just be text at this point (text acting as a button with no background). To see the background behind the button, you have to do something very random. I have gone through and converted all of the classes to be mtasc-friendly and this was the only part that still doesn’t make complete sense to me, but it works. In BaseButton.as, add the following code to around line 88:

    For some reason, even though BaseButton extends UIObject, without the above statement the call to set background does not automatically go up the chain to UIObject without explicitly forcing it to. If you compile now, you should see the background behind the button. You now have a fully working example of a Metaliq component being compiled with mtasc.

  10. Continue along with these steps and slowly and surely you will start to make headway through the rest of the classes. Be forewarned there are a lot of errors to fix to make the entire component set mtasc compliant. But once you do, your life will be much simpler and your compiling will be MUCH faster.

Enjoy and feel free to comment with questions below.

About the author

Mark

View all posts

4 Comments

  • Thank you very much for the solution. When I tried to do the same thing for a ComboBox, i got some Warnings from FlashDevelop.

    Here are they..
    ============================================
    Warning : The MovieClip com.metaliq.controls.ComboBox:ComboBackground needs the class com.metaliq.skins.gskin1.ComboBackground which was not compiled :
    Please force compilation of this class by adding it to the commandline.
    Warning : The MovieClip com.metaliq.controls.SmartClipList:DemoRowRenderer needs the class com.metaliq.controls.DemoRowRenderer which was not compiled :
    Please force compilation of this class by adding it to the commandline.
    Warning : The MovieClip com.metaliq.controls.ComboBox:ComboButton needs the class com.metaliq.controls.GraphicButton which was not compiled :
    Please force compilation of this class by adding it to the commandline.
    Warning : The MovieClip com.metaliq.controls.UIObject:Background needs the class com.metaliq.skins.gskin1.InsetBackground which was not compiled :
    Please force compilation of this class by adding it to the commandline.
    ================================

    I have given import commands in the Main class for the above classes. Still it gives me such warning.

  • You not only have to import the classes, but you need to instantiate the classes or mtasc still won’t include them.
    So for com.metaliq.skins.gskin1.ComboBackground:

    You would import the class and do something like:

    var cb:ComboBackground;
    delete cb;

  • Mark wrote: “… You not only have to import the classes, but you need to instantiate the classes or mtasc still won’t include them.”

    You can also use the -pack directive on Mtasc to compile classes in a particular package.
    For the example you provided, you might have used

    mtasc -pack com/metaliq/skins/gskin1 etc…

    to force the compiler to include the gskin1 package.

Leave a Reply

Your email address will not be published. Required fields are marked *