2010-04-14 42 views
0

我正在使用actionscript來使用來自HTTP請求的JSON數據動態生成SWF。我收到有關creationComplete的數據並嘗試生成類似結構的樹。我不會同時創建整棵樹。我創建了2個級別,1級和2級。我的目標是在代表樹節點的面板上附加自定義事件。當用戶點擊面板時,它會調度自定義事件並嘗試生成下一個級別。所以,它是這樣的: 在創建完成 - >獲取JSON->創建頂級拖拽級別 - >點擊級別2->創建級別2和級別3 - >點擊級別3>創建級別3和4。 …等等等等。我使用此電子郵件附加了我的代碼。請看看它,如果您有任何提示,說明如果您需要繪製總級別號爲「n」(其中n = 0到100)的樹,我應該如何在CustomPageClickEvent類中攜帶數據。 [代碼]關於在使用actionscript的自定義事件中攜帶數據的疑問

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)}); 
    } 

[/代碼] 預先感謝。 Palash

+0

你的代碼是難以閱讀,你認爲你可以修正格式/縮進第一? – davr 2010-04-28 22:00:21

回答

0

完全忘了我沒有足夠的代表處進行編輯...

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)}); 
}