守望者--AIR技术交流

标题: 使用 VISUAL STUDIO EXPRESS 2012 开发FLASCC项目 [打印本页]

作者: 破晓    时间: 2014-12-29 16:04
标题: 使用 VISUAL STUDIO EXPRESS 2012 开发FLASCC项目
本帖最后由 破晓 于 2015-1-16 15:35 编辑

Visual Studio Express 2012是Visual Studio  的免费版本,Visual Studio 具有代码提示功能,用他来编写编写FlassCC的c++代码就像使用FlashDevelop编写As3一样方便,如果是较大的项目它也能很好的管理代码。

第一步:下载安装C++ 开发工具 Visual Studio 及配置

下载的Visual Studio 的免费版本Visual Studio 2012 Express for Windows Desktop


[attach]103[/attach]


安装完成后拷贝 C:\flascc\sdk\usr\include 目录下的AS3、AS3++和Flash++.h到 Visual Studio的安装目录 E:\Program Files\Microsoft Visual Studio 11.0\VC\include 下


[attach]3[/attach]


[attach]5[/attach]


第二:编写代码编写一个简单的例子,实现一个长方形图形的旋转,先写出as3代码,顺便对比下与用c++编写的区别。As3代码:

  1. package
  2. {
  3.     import flash.display.Shape;
  4.     import flash.display.Sprite;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;

  8.     /**
  9.      * ...
  10.      * @author coler
  11.      */
  12.     public class Main extends Sprite
  13.     {
  14.         private var shape:Shape;
  15.         public function Main():void
  16.         {
  17.             // 设置舞台
  18.             stage.scaleMode = StageScaleMode.NO_SCALE;
  19.             stage.align = StageAlign.LEFT;
  20.             stage.frameRate = 60;
  21.             // 画一个长方形并旋转
  22.             shape = new Shape();
  23.             shape.x = 100;
  24.             shape.y = 100;
  25.             shape.graphics.beginFill(0x0F0091);
  26.             shape.graphics.drawRect(0, 0, 50, 50);
  27.             shape.graphics.endFill();
  28.             stage.addChild(shape);
  29.             stage.addEventListener(Event.ENTER_FRAME, onFrame);
  30.         }

  31.         private function onFrame(e:Event):void
  32.         {
  33.             shape.rotation += 1;
  34.         }

  35.     }

  36. }
复制代码
用FalshDevelop编译并运行
[attach]6[/attach]


用c++编写,实现相同的功能:打开Visual Studio 新建c++项目MyFlashC++,选择模版Visual C++,选择空项目

[attach]7[/attach]


使用类向导添加一个类

[attach]8[/attach]


生成类Main

[attach]9[/attach]


删除 Main.cpp 和Main.h的所有内容,开始写我们自己的代码。开始编写c++代码使用Visual Studio编写代码的好处就是它可以像在FlashDevelop里编写代码一样方便,它有良好的代码提示功能



[attach]10[/attach]
与编写AS不同的是访问属性变成的指针的方式


[attach]11[/attach]



完整的代码:


  1. #include <Flash++.h>
  2. // 使用命名空间
  3. // using namespace flash::events; 相当于as里的 import flash.events.*;
  4. using namespace AS3::ui;
  5. using namespace flash::events;
  6. using namespace flash::display;
  7. // 定义变量
  8. Stage stage;
  9. Shape shape;

  10. static var onFrame(void *arg, var as3Args){
  11.     shape->rotation = shape->rotation + 1; // 不能写成shape->rotation += 1;因为没有实现重载+=运算符。
  12.     return internal::_undefined;
  13. }
  14. int main(){
  15.     // 设置舞台
  16.     stage = internal::get_Stage();
  17.     stage->scaleMode = StageScaleMode::NO_SCALE;
  18.     stage->align = StageAlign::LEFT;// C++里访问类属性用::
  19.     stage->frameRate = 60;// 实例属性的访问用指针方式
  20.     // 画一个长方形并旋转
  21.     shape = Shape::_new();
  22.     shape->x = 100;
  23.     shape->y = 100;

  24.     Graphics graphics = shape->graphics;
  25.     graphics->beginFill(0x0F0091);
  26.     graphics->drawRect(0,0,50,50);
  27.     graphics->endFill();

  28.     stage->addChild(shape);

  29.     stage->addEventListener(Event::ENTER_FRAME,Function::_new(onFrame,NULL));
  30.     AS3_GoAsync();

  31. }
复制代码

准备编译

在C:\flascc\tutorials\下新建MyFlashC++目录,把Main.cpp拷贝到该目录,新建文件Makefile,内容如下:


  1. MyFlashC++: check
  2. @echo "-------- MyFlashC++ --------"
  3. @echo "\n 编译中....:"
  4. "$(FLASCC)/usr/bin/g++" Main.cpp -emit-swf -swf-size=200x200 -lFlash++ -lAS3++ -o c++Main.swf

  5. include ../Makefile.common

  6. clean:
  7. rm -f *.swf
复制代码
切换目录到 MyFlashC++执行编译命令

[attach]12[/attach]







欢迎光临 守望者--AIR技术交流 (http://www.airmyth.com/)