关于使用actionscript在自定义事件中携带数据的疑问

发布于 2024-08-29 02:36:39 字数 5212 浏览 3 评论 0原文

我正在使用actionscript 来使用来自HTTP 请求的JSON 数据动态生成SWF。我收到creationComplete 上的数据并尝试生成树状结构。我不会同时创建整棵树。我创建了 2 个级别,即级别 1 和级别 2。我的目标是将自定义事件附加到代表树节点的面板上。当用户单击面板时,它会调度自定义事件并尝试生成下一个级别。所以,事情是这样的: 创建完成后->获取 JSON->创建顶部两个级别 ->点击2级->创建级别 2 和级别 3 ->点击第3级->创建级别 3 和 4。……等等。我在这封电子邮件中附上了我的代码。请看一下它,如果您需要绘制总级别数 =“n”(其中 n = 0 到 100)的树,您是否有任何关于如何执行此操作的提示 我应该在 CustomPageClickEvent 类中携带数据吗? [代码]

import com.iwobanas.effects.*;
 import flash.events.MouseEvent;
 import flash.filters.BitmapFilterQuality;
 import flash.filters.BitmapFilterType;
 import flash.filters.GradientGlowFilter;
 import mx.controls.Alert;
 private var roundedMask:Sprite;
    private var panel:NewPanel;
    public var oldPanelIds:Array = new Array();

    public var pages:Array = new Array();

    public var delPages:Array = new Array();

    public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
   panel = new NewPanel(chld);
            panel.title = title;
            panel.name=title;
            panel.width = 100;
            panel.height = 80;
            panel.x=pos+5;
            panel.y=40;

    var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
   gradientGlow.distance = 0;
   gradientGlow.angle = 45;
   gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
   gradientGlow.alphas = [0, 1];
   gradientGlow.ratios = [0, 255];
   gradientGlow.blurX = 10;
   gradientGlow.blurY = 10;
   gradientGlow.strength = 2;
   gradientGlow.quality = BitmapFilterQuality.HIGH;
   gradientGlow.type = BitmapFilterType.OUTER;
   panel.filters =[gradientGlow];
   this.rawChildren.addChild(panel);
   pages.push(panel);
   panel.addEventListener(MouseEvent.CLICK,
    function(e:MouseEvent){onClickHandler(e,title,chld)});
   this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
    function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});  
 }
 public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {

   for each(var stp1:NewPanel in pages){
       if(stp1.title==title){
        var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
     eventObj.panelClicked = stp1;
     dispatchEvent(eventObj); 
       }
      }
 }

   private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {

         Alert.show("onCustomPanelClicked" + title);
     var panel:NewPanel;
     for each(var stp:NewPanel in pages){
       startAnimation(e,stp);
     }
     if(title == e.panelClicked.title){
      panel = new NewPanel(null);
            panel.title = title;
            panel.name=title;
            panel.width = 150;
            panel.height = 80;
            panel.x=100;
            panel.y=40;
            this.rawChildren.addChild(panel);
            var slideRight:SlideRight = new SlideRight();
            slideRight.target=panel;
            slideRight.duration=750;
            slideRight.showTarget=true;
            slideRight.play();
            var jsonData = this.map.getValue(title);
            var posX:Number = 50;
            var posY:Number = 175;
         for each ( var pnl:NewPanel in pages){
          pages.pop();
         }
         for each ( var stp1:Object in jsonData.children){
          panel = new NewPanel(null);
          panel.title = stp1.text;
          panel.name=stp1.id;
          panel.width = 100;
          panel.id=stp1.id;
          panel.height = 80;
          panel.x = posX;
          panel.y=posY;
          posX+=150;
          var s:String="hi" + stp1.text;
          panel.addEventListener(MouseEvent.CLICK,
           function(e:MouseEvent){onChildClick(e,s);});
           this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
          function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
          this.rawChildren.addChild(panel);
          pages.push(panel);
          this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
          function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)}); 
           var slide:SlideUp = new SlideUp();
                slide.target=panel;
                slide.duration=1500;
                slide.showTarget=false;
                slide.play();
            }       
     }

   }
   public function onChildClick(e:MouseEvent,s:String):void {
        for each(var stp1:NewPanel in pages){
            if(stp1.title==e.currentTarget.title){
              var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
              eventObj.panelClicked = stp1;
              dispatchEvent(eventObj); 
            }
        } 
 }      

 private function onCustomPnlClicked(e:CustomPageClickEvent):void {
    for each ( var pnl:NewPanel in pages){
          pages.pop();
         }
    }   
    private function fadePanel(event:Event,panel:NewPanel):void{
         panel.alpha -= .005;
        if (panel.alpha <= 0){
            panel.removeEventListener(Event.ENTER_FRAME, 
            function(e:Event){fadePanel(e,panel);});
        };
        panel.title=""; 
    }

    private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
        panel.addEventListener(Event.ENTER_FRAME, 
        function(e:Event){fadePanel(e,panel)});
    }

[/代码] 提前致谢。 帕拉什

I am working on actionscript to generate a SWF dynamically using JSON data coming from an HTTP request. I receive the data on creationComplete and try to generate a tree like structure. I don’t create the whole tree at the same time. I create 2 levels, level 1 and level 2. My goal is to attach custom events on the panels which represent tree nodes. When users click the panels, it dispatches custom events and try to generate the next level. So, it goes like this :
On creation complete -> get JSON-> create top tow levels -> click on level 2-> create the level 2 and level 3 -> click on level 3-> create level 3 and 4. …and so on and so on. I am attaching my code with this email. Please take a look at it and if you have any hints on how you would do this if you need to paint a tree having total level number = “n” where n = 0 to 100
Should I carry the data around in CustomPageClickEvent class.
[code]

import com.iwobanas.effects.*;
 import flash.events.MouseEvent;
 import flash.filters.BitmapFilterQuality;
 import flash.filters.BitmapFilterType;
 import flash.filters.GradientGlowFilter;
 import mx.controls.Alert;
 private var roundedMask:Sprite;
    private var panel:NewPanel;
    public var oldPanelIds:Array = new Array();

    public var pages:Array = new Array();

    public var delPages:Array = new Array();

    public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
   panel = new NewPanel(chld);
            panel.title = title;
            panel.name=title;
            panel.width = 100;
            panel.height = 80;
            panel.x=pos+5;
            panel.y=40;

    var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
   gradientGlow.distance = 0;
   gradientGlow.angle = 45;
   gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
   gradientGlow.alphas = [0, 1];
   gradientGlow.ratios = [0, 255];
   gradientGlow.blurX = 10;
   gradientGlow.blurY = 10;
   gradientGlow.strength = 2;
   gradientGlow.quality = BitmapFilterQuality.HIGH;
   gradientGlow.type = BitmapFilterType.OUTER;
   panel.filters =[gradientGlow];
   this.rawChildren.addChild(panel);
   pages.push(panel);
   panel.addEventListener(MouseEvent.CLICK,
    function(e:MouseEvent){onClickHandler(e,title,chld)});
   this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
    function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});  
 }
 public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {

   for each(var stp1:NewPanel in pages){
       if(stp1.title==title){
        var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
     eventObj.panelClicked = stp1;
     dispatchEvent(eventObj); 
       }
      }
 }

   private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {

         Alert.show("onCustomPanelClicked" + title);
     var panel:NewPanel;
     for each(var stp:NewPanel in pages){
       startAnimation(e,stp);
     }
     if(title == e.panelClicked.title){
      panel = new NewPanel(null);
            panel.title = title;
            panel.name=title;
            panel.width = 150;
            panel.height = 80;
            panel.x=100;
            panel.y=40;
            this.rawChildren.addChild(panel);
            var slideRight:SlideRight = new SlideRight();
            slideRight.target=panel;
            slideRight.duration=750;
            slideRight.showTarget=true;
            slideRight.play();
            var jsonData = this.map.getValue(title);
            var posX:Number = 50;
            var posY:Number = 175;
         for each ( var pnl:NewPanel in pages){
          pages.pop();
         }
         for each ( var stp1:Object in jsonData.children){
          panel = new NewPanel(null);
          panel.title = stp1.text;
          panel.name=stp1.id;
          panel.width = 100;
          panel.id=stp1.id;
          panel.height = 80;
          panel.x = posX;
          panel.y=posY;
          posX+=150;
          var s:String="hi" + stp1.text;
          panel.addEventListener(MouseEvent.CLICK,
           function(e:MouseEvent){onChildClick(e,s);});
           this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
          function(e:CustomPageClickEvent){onCustomPnlClicked(e)});
          this.rawChildren.addChild(panel);
          pages.push(panel);
          this.addEventListener(CustomPageClickEvent.PANEL_CLICKED,
          function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)}); 
           var slide:SlideUp = new SlideUp();
                slide.target=panel;
                slide.duration=1500;
                slide.showTarget=false;
                slide.play();
            }       
     }

   }
   public function onChildClick(e:MouseEvent,s:String):void {
        for each(var stp1:NewPanel in pages){
            if(stp1.title==e.currentTarget.title){
              var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
              eventObj.panelClicked = stp1;
              dispatchEvent(eventObj); 
            }
        } 
 }      

 private function onCustomPnlClicked(e:CustomPageClickEvent):void {
    for each ( var pnl:NewPanel in pages){
          pages.pop();
         }
    }   
    private function fadePanel(event:Event,panel:NewPanel):void{
         panel.alpha -= .005;
        if (panel.alpha <= 0){
            panel.removeEventListener(Event.ENTER_FRAME, 
            function(e:Event){fadePanel(e,panel);});
        };
        panel.title=""; 
    }

    private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
        panel.addEventListener(Event.ENTER_FRAME, 
        function(e:Event){fadePanel(e,panel)});
    }

[/code]
Thanks in advance.
Palash

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-09-05 02:36:39

完全忘记了我没有足够的代表来编辑......

import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;

private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();

public var pages:Array = new Array();

public var delPages:Array = new Array();

public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
    panel = new NewPanel(chld);
    panel.title = title;
    panel.name=title;
    panel.width = 100;
    panel.height = 80;
    panel.x=pos+5;
    panel.y=40;

    var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
    gradientGlow.distance = 0;
    gradientGlow.angle = 45;
    gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
    gradientGlow.alphas = [0, 1];
    gradientGlow.ratios = [0, 255];
    gradientGlow.blurX = 10;
    gradientGlow.blurY = 10;
    gradientGlow.strength = 2;
    gradientGlow.quality = BitmapFilterQuality.HIGH;
    gradientGlow.type = BitmapFilterType.OUTER;

    panel.filters = [gradientGlow];

    this.rawChildren.addChild(panel);
    pages.push(panel);

    panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onClickHandler(e,title,chld)});
    this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});  
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
    for each(var stp1:NewPanel in pages){
        if(stp1.title==title){
            var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
            eventObj.panelClicked = stp1;
            dispatchEvent(eventObj); 
        }
    }
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {

    Alert.show("onCustomPanelClicked" + title);
    var panel:NewPanel;
    for each(var stp:NewPanel in pages){
        startAnimation(e,stp);
    }
    if(title == e.panelClicked.title){
        panel = new NewPanel(null);
        panel.title = title;
        panel.name=title;
        panel.width = 150;
        panel.height = 80;
        panel.x=100;
        panel.y=40;
        this.rawChildren.addChild(panel);

        var slideRight:SlideRight = new SlideRight();
        slideRight.target=panel;
        slideRight.duration=750;
        slideRight.showTarget=true;
        slideRight.play();

        var jsonData = this.map.getValue(title);
        var posX:Number = 50;
        var posY:Number = 175;
        for each ( var pnl:NewPanel in pages){
            pages.pop();
        }
        for each ( var stp1:Object in jsonData.children){
            panel = new NewPanel(null);
            panel.title = stp1.text;
            panel.name=stp1.id;
            panel.width = 100;
            panel.id=stp1.id;
            panel.height = 80;
            panel.x = posX;
            panel.y=posY;
            posX += 150;

            var s:String="hi" + stp1.text;
            panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onChildClick(e,s);});
            this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPnlClicked(e)});

            this.rawChildren.addChild(panel);
            pages.push(panel);
            this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)}); 
            var slide:SlideUp = new SlideUp();
            slide.target=panel;
            slide.duration=1500;
            slide.showTarget=false;
            slide.play();
        }       
    }
}
public function onChildClick(e:MouseEvent,s:String):void {
    for each(var stp1:NewPanel in pages){
        if(stp1.title==e.currentTarget.title){
            var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
            eventObj.panelClicked = stp1;
            dispatchEvent(eventObj); 
        }
    } 
}      
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
    for each ( var pnl:NewPanel in pages){
        pages.pop();
    }
}   
private function fadePanel(event:Event,panel:NewPanel):void{
    panel.alpha -= .005;
    if (panel.alpha <= 0){
        panel.removeEventListener(Event.ENTER_FRAME, 
        function(e:Event){fadePanel(e,panel);});
    };
    panel.title=""; 
}

private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
    panel.addEventListener(Event.ENTER_FRAME, 
    function(e:Event){fadePanel(e,panel)});
}

completely forgot i don't have enough rep to edit...

import com.iwobanas.effects.*;
import flash.events.MouseEvent;
import flash.filters.BitmapFilterQuality;
import flash.filters.BitmapFilterType;
import flash.filters.GradientGlowFilter;
import mx.controls.Alert;

private var roundedMask:Sprite;
private var panel:NewPanel;
public var oldPanelIds:Array = new Array();

public var pages:Array = new Array();

public var delPages:Array = new Array();

public function DrawPlaybook(pos:Number,title:String,chld:Object):void {
    panel = new NewPanel(chld);
    panel.title = title;
    panel.name=title;
    panel.width = 100;
    panel.height = 80;
    panel.x=pos+5;
    panel.y=40;

    var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
    gradientGlow.distance = 0;
    gradientGlow.angle = 45;
    gradientGlow.colors = [0xFFFFF0, 0xFFFFFF];
    gradientGlow.alphas = [0, 1];
    gradientGlow.ratios = [0, 255];
    gradientGlow.blurX = 10;
    gradientGlow.blurY = 10;
    gradientGlow.strength = 2;
    gradientGlow.quality = BitmapFilterQuality.HIGH;
    gradientGlow.type = BitmapFilterType.OUTER;

    panel.filters = [gradientGlow];

    this.rawChildren.addChild(panel);
    pages.push(panel);

    panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onClickHandler(e,title,chld)});
    this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)});  
}
public function onClickHandler(e:MouseEvent,title:String,chld:Object):void {
    for each(var stp1:NewPanel in pages){
        if(stp1.title==title){
            var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
            eventObj.panelClicked = stp1;
            dispatchEvent(eventObj); 
        }
    }
}
private function onCustomPanelClicked(e:CustomPageClickEvent,title:String):void {

    Alert.show("onCustomPanelClicked" + title);
    var panel:NewPanel;
    for each(var stp:NewPanel in pages){
        startAnimation(e,stp);
    }
    if(title == e.panelClicked.title){
        panel = new NewPanel(null);
        panel.title = title;
        panel.name=title;
        panel.width = 150;
        panel.height = 80;
        panel.x=100;
        panel.y=40;
        this.rawChildren.addChild(panel);

        var slideRight:SlideRight = new SlideRight();
        slideRight.target=panel;
        slideRight.duration=750;
        slideRight.showTarget=true;
        slideRight.play();

        var jsonData = this.map.getValue(title);
        var posX:Number = 50;
        var posY:Number = 175;
        for each ( var pnl:NewPanel in pages){
            pages.pop();
        }
        for each ( var stp1:Object in jsonData.children){
            panel = new NewPanel(null);
            panel.title = stp1.text;
            panel.name=stp1.id;
            panel.width = 100;
            panel.id=stp1.id;
            panel.height = 80;
            panel.x = posX;
            panel.y=posY;
            posX += 150;

            var s:String="hi" + stp1.text;
            panel.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){onChildClick(e,s);});
            this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPnlClicked(e)});

            this.rawChildren.addChild(panel);
            pages.push(panel);
            this.addEventListener(CustomPageClickEvent.PANEL_CLICKED, function(e:CustomPageClickEvent){onCustomPanelClicked(e,title)}); 
            var slide:SlideUp = new SlideUp();
            slide.target=panel;
            slide.duration=1500;
            slide.showTarget=false;
            slide.play();
        }       
    }
}
public function onChildClick(e:MouseEvent,s:String):void {
    for each(var stp1:NewPanel in pages){
        if(stp1.title==e.currentTarget.title){
            var eventObj:CustomPageClickEvent = new CustomPageClickEvent("panelClicked");
            eventObj.panelClicked = stp1;
            dispatchEvent(eventObj); 
        }
    } 
}      
private function onCustomPnlClicked(e:CustomPageClickEvent):void {
    for each ( var pnl:NewPanel in pages){
        pages.pop();
    }
}   
private function fadePanel(event:Event,panel:NewPanel):void{
    panel.alpha -= .005;
    if (panel.alpha <= 0){
        panel.removeEventListener(Event.ENTER_FRAME, 
        function(e:Event){fadePanel(e,panel);});
    };
    panel.title=""; 
}

private function startAnimation(event:CustomPageClickEvent,panel:NewPanel):void{
    panel.addEventListener(Event.ENTER_FRAME, 
    function(e:Event){fadePanel(e,panel)});
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文