zoukankan      html  css  js  c++  java
  • ActionsScript 3.0简易涂鸦板

    使用的编辑器是FlashDevelop(汉化版)

    需要注意的是,该例子使用到了Button (属于flash cs3/cs4 中fl组件,位于fl.controls包下,而此编辑器默认不包含fl包)

    解决办法:

    1、在flash cs3/cs4中新建一个fla文件,打开组件库(快捷键Ctrl+F7) 将需要用到的组件拖到舞台,如下图:

    未命名

    2、打开菜单栏中“文件”——》“发布设置”(快捷键Ctrl+Shift+F12)

    选中flash项,勾选 “导出swc”

    未命名

    3、保存fla,ctrl+enter 导出影片,在该fla文件同级目录下会有一个同名的且后缀名为.swc的文件,将此文件copy并粘贴至FlashDevelop中bin目录下,默认为正常色,右击选中该swc组件包,点击选中“Add To Library”

    未命名

    代码中就可以使用Button组件了

    private var button:Button;

    button = new Button;
    button.label = "点击清空舞台";
    addChild(button);
    button.addEventListener(MouseEvent.CLICK, onclickHandler);

    点击下载flash cs4 swc组件>>

    下面就是coding了,在Main.as类中输入下面的代码,保存并运行即可看到效果 ^_^

    未命名

    上代码:

    package 
    {
    	import fl.controls.Button;
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    	
    	/**
    	 * ...
    	 * @author ZhangYi
    	 */
    	public class Main extends Sprite 
    	{
    		private var button:Button;
    		
    		public function Main():void 
    		{
    			if (stage) init();
    			else addEventListener(Event.ADDED_TO_STAGE, init);
    		}
    		
    		private function init(e:Event = null):void 
    		{
    			removeEventListener(Event.ADDED_TO_STAGE, init);
    			
    			graphics.lineStyle(1, 0, 1);
    			
    			//创建button并监听其MouseEvent.CLICK事件
    			button = new Button;
    			button.label = "点击清空舞台";
    			addChild(button);
    			button.addEventListener(MouseEvent.CLICK, onclickHandler);
    			
    			//监听舞台的MouseEvent.MOUSE_DOWN、MouseEvent.MOUSE_UP事件
    			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
    			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
    		}
    		
    		private function onMouseDownHandler(event:MouseEvent):void {
    			graphics.moveTo(mouseX, mouseY);
    			
    			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveHandler);
    		}
    		
    		private function onMouseUpHandler(event:MouseEvent):void {
    			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMoveHandler);
    		}
    		
    		private function onMouseMoveHandler(event:MouseEvent):void {
    			graphics.lineTo(mouseX, mouseY);
    		}
    		
    		private function onclickHandler(event:MouseEvent):void {
    			graphics.clear();
    			
    			graphics.lineStyle(1, 0, 1);
    		}
    		
    	}
    	
    }
  • 相关阅读:
    《Real Time 3D Terrain Engines Using C++ And DirectX9》(实时地形引擎)随书源码
    (转)ogreUML类图
    (转)导弹跟踪算法
    转:正则表达式语法
    读取数据
    Python lambda用法及其与def的区别
    转Vb6.0安装失败解决办法,完全卸载VB(提高班里win7没装上VB的可以看看,我实验成功了)
    vb imagelist 作用
    二叉树的实现
    转:Python语言编程学习资料(电子书+视频教程)下载汇总:
  • 原文地址:https://www.cnblogs.com/meteoric_cry/p/1818118.html
Copyright © 2011-2022 走看看