How to get FDT to ignore some “erroneous” code

December 19th, 2009 by Slav

Have been using FDT for about 3 and a half years now, on many occasions I came across a code that , although perfectly compilable (both by mxmlc and flash IDE), FDT thought it contained errors.

For example when code contained some “clever” trinary operator arguments, or a javascript code segments wrapped in CDATA …

Anyway, I came across a simple way to make FDT to ignore such code.

If you place the problematic code inside a /*FDT_IGNORE*/ …. /*FDT_IGNORE*/ comments, FDT will not parse such code and therefore will not mark it as code containing syntactic error. Goodbye red marks !

However .. on the other side, if such code contains a functions or variables that other classes refer to, FDT will not be able to find those references in the “ignored” sections.

So use it with caution !

Posted in AS3, FDT, flash | 2 Comments »

AttachMovie in AS3 ? Now possible! (also attachBitmapData ;)

November 2nd, 2009 by Slav

I code in AS3 for quite a while now, and don’t get me wrong, I do love it and I NEVER want to go back to as2.

However; there are some things I wish remained in AS3 that were possible to do in AS2.

Things like “eval” and “attachMovie” comes to mind…

Why attachMovie ? Isn’t it perfectly possible to do addChild(new WhatewerClass()) ?

Yes and no. The problem is if you don’t develop in Flash IDE, but in more sophisticated code editors like FDT, FlashDevelop or Flex.

Let’s say you have a graphical asset sitting in your library, it needs no interactivity so you don’t create any class for it. It simply extends MovieClip and has a linkage name “Asset1″ assign to it.

Now the moment , in your code you decide to attach it to your display container via addChild(new Asset1())none of the code editors I mentioned above will know about Asset1 as that Asset1 is a class created by flash IDE only when the fla is being compiled and therefore is only available during runtime. So they will mark it as erroneous class reference. Of course , swf will compile just fine, but that’s not the point :) You don’t want to have your project covered in errors of some of which are not really error and need to remember which ones are not real.. !

There are several solutions to this of course.

One I used, is to compile swc from the fla, so the every linked library assets are available to FDT/flash develop/flex for reference. The trouble with this solution is you have to keep the swc file updated which isn’t always straightforward.. For example flex sometimes doesn’t pick up that swc have been changed, you have to delete swc and then re-publish it to force it to recognise change. Similar situation happens with FDT sometimes. As well as you can into a situation where you get into a sort of a recursive error cycle , where swf doesn’t compile correctly because compiling that swf requires some assets from swc that aren’t there yet because project’s swc doesn’t have that assets yet because it can’t be compiled before the project doesn’t have those errors..  

The solution I devised instead is much simpler and mimic the old as2 “attachMovie” functionality.

Taking advantage of built in “getDefinitionByName” command from flash.utils package we can turn the asset into a class by giving it it’s linkage ID . As that class is compiled into swf it will be available during runtime - so that will work fine.

During authoring time it won’t flag up as error as well as it’s typed correctly to MovieClip (so sprite will work as well).

So I wrote a wrapper utility class that has 2 functions :

attachMovie - expect a linkage name and returns a MovieClip instance
attachBitmapData - expect a linkage name and returns BitmapData

this is a code for attaching the library assets used in the demo bellow :

  private function attachAsset1():void
  {
   var asset1:Sprite = MCUtils.attachMovie("Asset1");
   asset1.x = 10;
   asset1.y = 8;
   this.addChild(asset1);
  }
 
  private function attachGirl():void
  {
   var girlBmp:BitmapData = MCUtils.attachBitmapData("Girl");
   var girlBitmap:Bitmap = new Bitmap(girlBmp);
   girlBitmap.x = 10;
   girlBitmap.y = 85;
   this.addChild(girlBitmap);
  }

Demo :

Attach Movie Zip

Posted in AS3, FDT, Flex, flash | 9 Comments »

Refactoring in FDT 1.5

October 29th, 2007 by Slav

While only FTD3 has fully featured refactoring a simple file operations based refactoring can be found in FTD 1.5 or perhaps even earlier versions.

For some reason it is unchecked by default, but can be found here :

Eclipse > Window > Preferences > FDT > Refactoring > Flash Explorer File Operations Read the rest of this entry »

Posted in FDT, flash | No Comments »

FDT Code Templates

April 8th, 2007 by Slav

This is my AS2 code template document for FDT. It contains code snippets, all can be activated by starting to type the name for the snippet and then pressing ctrl+Space.

For example to get all the code needed to implement EventDispatcher for your class you need to first import this template xml (in FDT 1.5 this is done via Window > Preferences > FDT > Editor > Templates > Import) then type “ed” and press Ctrl+Space. Read the rest of this entry »

Posted in AS2, FDT | No Comments »