Editing/Authoring Actionscript3 Classes In IntelliJ IDEA

I wanted to see whether it was viable to use IntelliJ 8 as an IDE for creating complete Flash applications (for writing Actionscript). By default, the application allows you to create Flex applications and creates a "HelloWorld" app to get you started. But at first it was unclear how I could write AS3 classes and compile them without jumping over to flash or using FlexBuilder. 

I spent some time today dealing with issues regarding certain flash Objects (namely the Stage) being "null" and after some reading, I discovered this was to do with timing - I read around online and after looking in many places, I pieced together this mxml file:


  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
  3.                 layout="absolute"  
  4.                 applicationComplete="init()"  
  5.                 horizontalScrollPolicy="off"  
  6.                 verticalScrollPolicy="off">  
  7.   
  8.     <mx:Script>  
  9.   <![CDATA[ 
  10.         import com.yourNamespaceHere.Shell; 
  11.         private function init():void { 
  12.             var shell:Shell = new Shell(); 
  13.             this.rawChildren.addChild(shell); 
  14.             shell.init(); 
  15.         } 
  16.   ]]>  
  17.  </mx:Script>  
  18. </mx:Application>  


This replaced the HelloWorld.mxml that IntelliJ provided and it does two things:

1. Waits until "applicationComplete" (so the 'stage' exists).

2. Runs a function called init(), this instantiates Shell.as and places it on the stage (as a 'raw' child element). Once shell has been instantiated, init() is run and this can do whatever you like really - instantiate other classes, place objects on the stage, etc. 

IntelliJ will use the Flex SDK's compiler to 'build' all of your project .as files; all you need to do is tell it where to find the Flex 3 SDK (in Leopard, it was installed by default in: /Applications/Adobe Flex Builder 3 Plug-in/sdks)

Once you've got some code written in the shell, you can use the IntelliJ debugger to run the app, inspect trace statements and so on. Although it's not quite as easy to "get up and go" with IntelliJ as it is with the FlexBuilder plugin (or application), it still makes authoring AS3 possible using IntelliJ.

Example Shell.as (will trace out the stage width and height):

  1. package com.yourNamespaceHere {  
  2. import flash.display.MovieClip;  
  3. public class Shell extends MovieClip  
  4. {  
  5.     public function init ( ):void{  
  6.         trace('shell :: init ', stage.stageWidth, stage.stageHeight);  
  7.     }  
  8.   
  9. }  


Hope this is useful to someone who had wanted to know how to use IntelliJ as an Actionscript IDE and who was finding the same issues I had been running into.

 

o-link : http://blog.msbbc.co.uk/2008/12/editingauthoring-actionscript-3-classes.html

 

你可能感兴趣的:(Flex,Flash,Adobe,idea,actionscript)