事件冒泡阻止event.stopPropagation()

简介:

package
{

import flash.display.*;
import flash.events.*;
import flash.text.*;

public class EventBubble extends Sprite
{
    private var msgTxt:TextField;
    public var msg_txt:TextField;
    private var father1:Sprite;
    private var father2:Sprite;
    private var child1:Sprite;
    private var child2:Sprite;

    public function EventBubble()
    {
        this.father1 = new Sprite();
        this.father2 = new Sprite();
        this.child1 = new Sprite();
        this.child2 = new Sprite();
        this.msgTxt = this.getChildByName("msg_txt") as TextField;
        this.father1.graphics.beginFill(6671615);
        this.father1.graphics.drawRect(0, 0, 180, 140);
        this.father1.graphics.endFill();
        this.father1.x = 0;
        this.father1.y = 0;
        addChild(this.father1);
        this.father2.graphics.beginFill(5854273);
        this.father2.graphics.drawRect(0, 0, 180, 140);
        this.father2.graphics.endFill();
        this.father2.x = this.father1.x + this.father1.width + 5;
        this.father2.y = this.father1.y;
        addChild(this.father2);
        this.child1.graphics.beginFill(5854273);
        this.child1.graphics.drawRect(0, 0, 80, 40);
        this.child1.graphics.endFill();
        this.child1.x = 20;
        this.child1.y = 20;
        this.father1.addChild(this.child1);
        this.child2.graphics.beginFill(6671615);
        this.child2.graphics.drawRect(0, 0, 80, 40);
        this.child2.graphics.endFill();
        this.child2.x = 20;
        this.child2.y = 20;
        this.father2.addChild(this.child2);
        this.father1.addEventListener(MouseEvent.CLICK, this.fatherClickHandler);
        this.father2.addEventListener(MouseEvent.CLICK, this.fatherClickHandler);
        this.child1.addEventListener(MouseEvent.CLICK, this.child1ClickHandler);
        this.child2.addEventListener(MouseEvent.CLICK, this.child2ClickHandler);
        return;
    }// end function

    private function fatherClickHandler(event:MouseEvent) : void
    {
        trace("冒了。");
        this.msgTxt.appendText("冒了。\n");
        return;
    }// end function

    private function child1ClickHandler(event:MouseEvent) : void
    {
        trace("冒泡了嗎?");
        this.msgTxt.appendText("冒泡了嗎?\n");
        return;
    }// end function

    private function child2ClickHandler(event:MouseEvent) : void
    {
        event.stopPropagation();
        trace("冒泡了嗎?");
        this.msgTxt.appendText("冒泡了嗎?\n");
        return;
    }// end function

}

}
本文转自jiahuafu博客园博客,原文链接http://www.cnblogs.com/jiahuafu/archive/2010/05/19/1739441.html如需转载请自行联系原作者

jiahuafu

相关文章
|
人工智能 计算机视觉
教程 |【阿里云.人脸识别】Access Key ID 和 Access Key Secret 查看方法
本章主要介绍阿里云.人脸识别 Access Key ID 和 Access Key Secret 查看方法。
|
Java Nacos Docker
微服务入门教程
微服务入门教程
236 2
|
C语言
C 语言文件处理全攻略:创建、写入、追加操作解析
在 C 语言中,您可以通过声明类型为 FILE 的指针,并使用 fopen() 函数来创建、打开、读取和写入文件:
415 0
|
存储 机器学习/深度学习 人工智能
一文读懂ChatGPT的工作原理
【7月更文挑战第24天】.一文读懂ChatGPT的工作原理
566 2
|
机器学习/深度学习
生物神经元与人工神经元
生物神经元与人工神经元
396 13
|
人工智能 自然语言处理 数据可视化
书生·浦语2.5开源,推理能力再创新标杆,怎么玩都在这里了!
上海人工智能实验室秉持“以持续的高质量开源赋能创新”理念,在为社区始终如一地提供高质量开源模型的同时,也将继续坚持免费商用授权。
|
数据采集 算法 数据处理
AIGC产业链是怎样的?
【1月更文挑战第9天】AIGC产业链是怎样的?
368 2
AIGC产业链是怎样的?
|
运维 数据可视化 安全
VR虚拟现实的七大应用领域
VR虚拟现实的七大应用领域
VR虚拟现实的七大应用领域
|
安全 前端开发 Java
【开题报告】基于SpringBoot的演唱会门票在线预定系统的设计与实现
【开题报告】基于SpringBoot的演唱会门票在线预定系统的设计与实现
806 0
|
存储 网络协议 Unix
NAS(Network Attached Storage)
NAS(Network Attached Storage)是一种网络存储设备,它可以通过网络连接提供数据存储和共享服务。NAS通常具有独立的操作系统和文件系统,可以通过网络协议(如NFS、CIFS、FTP等)提供文件共享、备份、存储等功能,这些功能可以被多个设备或用户同时访问和使用。
744 1