欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Adobe Flash Builder 4入门例子

文件-新建-ActionScript项目-HelloWorld。

HelloWorld.as里加trace代码
package
{
 import flash.display.Sprite;
 public class HelloWorld extends Sprite
 {
  public function HelloWorld()
  {
 trace("Hello world!");
  }
}
}
F11调试(不是运行),控制台会显示Hello World!注意:需要显示控制台(view->console)

1.

文件-新建-Flex项目-desktopApp-桌面(在AdobeAIR中运行)-完成
desktopApp.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="hello world">
 <mx:Style>
  Application{
   background-image:"";
   background-color:"";
   background-alpha:"0.5";
  }
 </mx:Style>
 <mx:Label text="hello AIR" horizontalCenter="0" verticalCenter="0"/>
</mx:WindowedApplication>
保存-运行(ctrl+F11)。

2.

文件-新建-ActionScript项目-webScriptApp-Web(在Adobe Flash Player中运行)-完成
webScriptApp.as:
package
{
 import flash.display.Sprite;
 import flash.text.*;
 [SWF(width="400",height="100",frameRate="25",backgroundColor="#ffffff")]
 public class sample_webdesigner extends Sprite
 {
  public var myText:TextField=new TextField();
  public function sample_webdesigner()
  {
   myText.autoSize=TextFieldAutoSize.LEFT;
   myText.text="web  designer";
   var myformat:TextFormat=new TextFormat();
   myformat.size=55;
   myformat.font="Verdana";
   myformat.color=0x336699;
   myText.setTextFormat(myformat);
   addChild(myText);
   
  }
 }
}
保存-运行(ctrl+F11)。

3.

桌面项目,新建MXML文件
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
 <s:layout>
  <s:BasicLayout/>
 </s:layout>
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <fx:Script>
  <![CDATA[

   private function init():void{
    systemManager.addEventListener(Event.ENTER_FRAME,lineMove);
   }
   function lineMove(event:Event):void{
    var distance:Number=Math.sqrt( Math.pow(this.mouseY-HR.y,2) + Math.pow(this.mouseX-VR.x,2) );
    dis_txt.text=String(Math.floor(distance));
    HR.y+=(this.mouseY-HR.y)*0.3;
    VR.x+=(this.mouseX-VR.x)*0.3;
   }
  ]]>
 </fx:Script>
 <mx:HRule x="0" y="291" width="743" id="HR" chromeColor="#FB19F3"/>
 <mx:VRule x="268" y="0" height="620" id="VR" chromeColor="#F709F4"/>
 <s:Label x="597" y="22" text="" width="55" height="32" fontSize="18" color="#F10D0D" fontWeight="bold" id="dis_txt"/>  
</s:WindowedApplication>

=======================

4.
osc.as:
// ActionScript file
package{
 import flash.display.Sprite;
 import flash.events.Event;
 public class osc extends Sprite{
  private var xangle:Number=0,yangle:Number=0;
  private var xradius:Number=100,yradius:Number=100;
  private var xround:Number=stage.stageWidth/2;
  private var yround:Number=stage.stageHeight/2;
  public function osc(){ 
   super();
   this.graphics.beginFill(0x3366ff,100);
   this.graphics.drawCircle(0,0,10);
   this.graphics.endFill();
   this.x=0;
   this.y=100;
   addChild(this);
   var circle:Sprite=new Sprite();
   circle.graphics.lineStyle(0.5,0x000000,0.6);
   circle.graphics.drawCircle(200,200,100);
   addChild(circle);
   addEventListener(Event.ENTER_FRAME,myEvent);
  }
  public function myEvent(event:Event):void{
   this.x=xround+ Math.cos(xangle) * xradius;
   this.y=yround+Math.sin(yangle)*yradius;
   xangle+=0.5;
   yangle+=0.5;
  }
 }
}
.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="drawPanel()">
 <s:layout>
  <s:BasicLayout/>
 </s:layout>
 <fx:Declarations>
  <!-- 将非可视元素(例如服务、值对象)放在此处 -->
 </fx:Declarations>
 <fx:Script>
  <![CDATA[   
   import osc; 
   import mx.core.UIComponent; 
   public function drawPanel():void{
    var componet:UIComponent=new UIComponent();
    var panel:osc=new osc();
    myCanvas.addChild(componet);
    componet.addChild(panel);
   }
  ]]>
 </fx:Script>
 <mx:Canvas x="0" y="0" width="100%" height="100%" id="myCanvas">
 </mx:Canvas>
</s:Application>


TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at osc()[E:\myAdobeFlashBuilderWP\AIRHelloWorld\src\osc.as:9]
 at oscTest/drawPanel()[E:\myAdobeFlashBuilderWP\AIRHelloWorld\src\oscTest.mxml:18]
 at oscTest/___oscTest_WindowedApplication1_applicationComplete()[E:\myAdobeFlashBuilderWP\AIRHelloWorld\src\oscTest.mxml:4]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.core::UIComponent/dispatchEvent()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
 at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\SystemManager.as:2682]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\preloaders\Preloader.as:582]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.preloaders::SparkDownloadProgressBar/initCompleteHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\preloaders\SparkDownloadProgressBar.as:1087]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.preloaders::Preloader/dispatchAppEndEvent()[E:\dev\hero_private\frameworks\projects\framework\src\mx\preloaders\Preloader.as:380]
 at mx.preloaders::Preloader/appCreationCompleteHandler()[E:\dev\hero_private\frameworks\projects\framework\src\mx\preloaders\Preloader.as:590]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at mx.core::UIComponent/dispatchEvent()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:13128]
 at mx.core::UIComponent/set initialized()[E:\dev\hero_private\frameworks\projects\framework\src\mx\core\UIComponent.as:1818]
 at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\LayoutManager.as:842]
 at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\hero_private\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]


来自  http://lichune88.blog.163.com/blog/static/6302706820115204135674/

普通分类: