博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
事件冒泡阻止event.stopPropagation()
阅读量:4080 次
发布时间:2019-05-25

本文共 2111 字,大约阅读时间需要 7 分钟。

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

    }

}

posted on 2010-05-19 17:37 阅读(...) 评论(...)

转载地址:http://rhpni.baihongyu.com/

你可能感兴趣的文章
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
多线程使用随机函数需要注意的一点
查看>>
getpeername,getsockname
查看>>
所谓的进步和提升,就是完成认知升级
查看>>
如何用好碎片化时间,让思维更有效率?
查看>>
No.182 - LeetCode1325 - C指针的魅力
查看>>
Encoding Schemes
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>
Java8 HashMap集合解析
查看>>
自定义 select 下拉框 多选插件
查看>>
linux和windows内存布局验证
查看>>
Linux常用统计命令之wc
查看>>
fastcgi_param 详解
查看>>
搞定Java面试中的数据结构问题
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Sum Root to leaf Numbers
查看>>
如何成为编程高手
查看>>