zoukankan      html  css  js  c++  java
  • 事件冒泡阻止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

        }
    }

  • 相关阅读:
    C#——数组
    javaScript数组移除指定对象或下标i,数组去重
    css实现左边div自适应宽度,右边宽度适应左边
    最短JS判断是否为IE6(!-[1,]&&!window.XMLHttpRequest)(转)
    java 获取微信 页面授权 获取用户openid
    鼠标滑轮滚动事件
    浏览器后退(返回)事件捕获
    一些常用的原生js方法(函数)
    简单瀑布流实现
    XMLHttpRequest对象的创建与用法
  • 原文地址:https://www.cnblogs.com/jiahuafu/p/1739441.html
Copyright © 2011-2022 走看看