Flash ActionScript 3.0 语言和组件参考Event(7)

2019-05-18 16:44

Flash ActionScript 3.0 语言和组件参考(Event)

flash.display.LoaderInfo.unload USER_IDLE 常量

public static const USER_IDLE:String = \运行时版本: AIR 1.0

Event.USER_IDLE 常量定义 userIdle 事件对象的 type 属性值。 此事件具有以下属性: 属性 bubbles target 另请参见

flash.desktop.NativeApplication.userIdle USER_PRESENT 常量

public static const USER_PRESENT:String = \运行时版本: AIR 1.0

Event.USER_PRESENT 常量定义 userPresent 事件对象的 type 属性值。 此事件具有以下属性: 属性 bubbles target 另请参见

flash.desktop.NativeApplication.userPresent 示例 如何使用示例

以下示例使用 EventExample 类和 Square 自定义类来说明如何管理事件冒泡。 package {

import flash.display.Sprite; import flash.events.Event;

import flash.events.MouseEvent;

public class EventExample extends Sprite {

public function EventExample() {

第 31 页 共 35 页

false

NativeApplication 对象。

cancelable false;没有要取消的默认行为。

false

NativeApplication 对象。

cancelable false;没有要取消的默认行为。

Flash ActionScript 3.0 语言和组件参考(Event)

var square_0:Square = new Square(300, 0x336633); addChild(square_0);

var square_1:Square = new Square(250, 0x669966); square_0.addChild(square_1);

var square_2:Square = new Square(200, 0x66CC66); square_1.addChild(square_2);

var square_3:Square = new Square(150, 0xAA0000); square_3.shouldBubble = false; square_2.addChild(square_3);

var square_4:Square = new Square(100, 0x66FF66); square_3.addChild(square_4);

var square_5:Square = new Square(50, 0xCC0000); square_5.shouldBubble = false; square_4.addChild(square_5);

this.addEventListener(MouseEvent.CLICK, clickHandler); }

private function clickHandler(e:Event):void { trace(\stage: \+ e.type + \event from \+ e.target.name + \called on \

trace(\ } } }

import flash.display.Sprite; import flash.events.Event;

import flash.events.MouseEvent;

class Square extends Sprite { private var sideLen:int; private var color:Number;

public var shouldBubble:Boolean = true;

public function Square(sideLen:int, color:Number) { this.sideLen = sideLen; this.color = color; init();

第 32 页 共 35 页

Flash ActionScript 3.0 语言和组件参考(Event)

draw(); }

private function init():void { buttonMode = true;

this.addEventListener(MouseEvent.CLICK, firstClickHandler); this.addEventListener(MouseEvent.CLICK, secondClickHandler); this.addEventListener(MouseEvent.CLICK, thirdClickHandler); }

private function draw():void {

this.graphics.beginFill(color);

this.graphics.drawRect(0, 0, sideLen, sideLen); }

private function firstClickHandler(e:Event):void {

trace(\\

if(!shouldBubble) {

e.stopPropagation(); } }

private function secondClickHandler(e:Event):void {

trace(\\

if(!shouldBubble) {

e.stopImmediatePropagation();

trace(\ } }

private function thirdClickHandler(e:Event):void {

trace(\\ } }

以下示例创建 ADDED 和 ADDED_TO_STAGE 事件以及 REMOVED 和 REMOVED_FROM_STAGE 事件之间区别的演示。单击 Sprite 将从舞台将其删除,同时还删除其中嵌套的所有内容。 例如,单击最大的 Sprite 将导致一个 REMOVED 事件和三个 REMOVED_FROM_STAGE 事件触发。 package {

第 33 页 共 35 页

Flash ActionScript 3.0 语言和组件参考(Event)

import flash.display.Sprite; import flash.events.*;

public class EventExample2 extends Sprite { public function EventExample2():void {

var parentSprite:Sprite = createSprite(\ var childSprite:Sprite = createSprite(\ var childOfChildSprite:Sprite = createSprite(\

trace(\ this.addChild(parentSprite); trace(\ parentSprite.addChild(childSprite); trace(\

childSprite.addChild(childOfChildSprite); }

private function createSprite(name:String,size:uint):Sprite { trace(\

var newSprite:Sprite = new Sprite(); newSprite.name = name;

newSprite.graphics.beginFill(0xFFFFFF * Math.random(),1); newSprite.graphics.drawRect(0,0,size,size); newSprite.graphics.endFill();

newSprite.addEventListener(Event.ADDED, spriteAdded); newSprite.addEventListener(Event.ADDED_TO_STAGE, spriteAddedToStage);

newSprite.addEventListener(Event.REMOVED, spriteRemoved); newSprite.addEventListener(Event.REMOVED_FROM_STAGE, spriteRemovedFromStage);

newSprite.addEventListener(MouseEvent.CLICK, remove); return newSprite; }

private function remove(event:Event) {

if(event.target == event.currentTarget) { trace(\ var target:Sprite = Sprite(event.target); target.parent.removeChild(target); } }

private function spriteRemovedFromStage(event:Event):void { trace(\event.currentTarget.name); }

第 34 页 共 35 页

Flash ActionScript 3.0 语言和组件参考(Event)

private function spriteRemoved(event:Event):void { trace(\event.currentTarget.name); }

private function spriteAddedToStage(event:Event):void { trace(\event.currentTarget.name); }

private function spriteAdded(event:Event):void {

trace(\event.currentTarget.name); } } }

? 2004-2008 Adobe Systems Incorporated. All rights reserved.

Sun Oct 26 2008, 02:41 AM -07:00

第 35 页 共 35 页


Flash ActionScript 3.0 语言和组件参考Event(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:化学实验室总账 Microsoft Word 文档

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: