本帖最后由 破晓 于 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
安装完成后拷贝 C:\flascc\sdk\usr\include 目录下的AS3、AS3++和Flash++.h到 Visual Studio的安装目录 E:\Program Files\Microsoft Visual Studio 11.0\VC\include 下
第二:编写代码编写一个简单的例子,实现一个长方形图形的旋转,先写出as3代码,顺便对比下与用c++编写的区别。As3代码: - package
- {
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.Event;
-
- /**
- * ...
- * @author coler
- */
- public class Main extends Sprite
- {
- private var shape:Shape;
- public function Main():void
- {
- // 设置舞台
- stage.scaleMode = StageScaleMode.NO_SCALE;
- stage.align = StageAlign.LEFT;
- stage.frameRate = 60;
- // 画一个长方形并旋转
- shape = new Shape();
- shape.x = 100;
- shape.y = 100;
- shape.graphics.beginFill(0x0F0091);
- shape.graphics.drawRect(0, 0, 50, 50);
- shape.graphics.endFill();
- stage.addChild(shape);
- stage.addEventListener(Event.ENTER_FRAME, onFrame);
- }
-
- private function onFrame(e:Event):void
- {
- shape.rotation += 1;
- }
-
- }
-
- }
复制代码 用FalshDevelop编译并运行
用c++编写,实现相同的功能:打开Visual Studio 新建c++项目MyFlashC++,选择模版Visual C++,选择空项目
使用类向导添加一个类
生成类Main
删除 Main.cpp 和Main.h的所有内容,开始写我们自己的代码。开始编写c++代码使用Visual Studio编写代码的好处就是它可以像在FlashDevelop里编写代码一样方便,它有良好的代码提示功能
与编写AS不同的是访问属性变成的指针的方式
完整的代码:
- #include <Flash++.h>
- // 使用命名空间
- // using namespace flash::events; 相当于as里的 import flash.events.*;
- using namespace AS3::ui;
- using namespace flash::events;
- using namespace flash::display;
- // 定义变量
- Stage stage;
- Shape shape;
-
- static var onFrame(void *arg, var as3Args){
- shape->rotation = shape->rotation + 1; // 不能写成shape->rotation += 1;因为没有实现重载+=运算符。
- return internal::_undefined;
- }
- int main(){
- // 设置舞台
- stage = internal::get_Stage();
- stage->scaleMode = StageScaleMode::NO_SCALE;
- stage->align = StageAlign::LEFT;// C++里访问类属性用::
- stage->frameRate = 60;// 实例属性的访问用指针方式
- // 画一个长方形并旋转
- shape = Shape::_new();
- shape->x = 100;
- shape->y = 100;
-
- Graphics graphics = shape->graphics;
- graphics->beginFill(0x0F0091);
- graphics->drawRect(0,0,50,50);
- graphics->endFill();
-
- stage->addChild(shape);
-
- stage->addEventListener(Event::ENTER_FRAME,Function::_new(onFrame,NULL));
- AS3_GoAsync();
-
- }
复制代码准备编译 在C:\flascc\tutorials\下新建MyFlashC++目录,把Main.cpp拷贝到该目录,新建文件Makefile,内容如下:
- MyFlashC++: check
- @echo "-------- MyFlashC++ --------"
- @echo "\n 编译中....:"
- "$(FLASCC)/usr/bin/g++" Main.cpp -emit-swf -swf-size=200x200 -lFlash++ -lAS3++ -o c++Main.swf
-
- include ../Makefile.common
-
- clean:
- rm -f *.swf
复制代码 切换目录到 MyFlashC++执行编译命令
|