network中的image


通过twaver.Utils.registerImage***方法,具体参考Demo

view plaincopy to clipboardprint?
代码: 
   [Embed(source="a.png")] 
   public static const imageName:Class; 
   Utils.registerImageByClass("a",imageName); 
然后Node.image="a"设置网元的图片。 


嗯,看了代码,有个疑问,是通过哪个语句决定哪个layer显示在上哪个显示在下?

LayerVectorDemo这个例子说的就是图层的操作,这是控制代码

view plaincopy to clipboardprint?
layerBox.moveSelectionToTop() 
network.selectionModel.addSelectionChangeListener(function(e:*):void{ 
               var node:Node = network.selectionModel.lastData as Node; 
               if(node != null){ 
                  var layer:ILayer = layerBox.getLayerByID(node.layerID); 
                  layerBox.selectionModel.setSelection(layer); 
               } 
            }); 
... 
DemoUtils.createButtonBar(layerToolbar, [ 
               DemoUtils.createButtonInfo("move selected rows to top", DemoImages.top, layerBox.moveSelectionToTop), 
               DemoUtils.createButtonInfo("move selected rows to up", DemoImages.up, layerBox.moveSelectionUp), 
               DemoUtils.createButtonInfo("move selected rows to down", DemoImages.down, layerBox.moveSelectionDown), 
               DemoUtils.createButtonInfo("move selected rows to bottom", DemoImages.bottom, layerBox.moveSelectionToBottom) 
            ]); 


--通过 layer加到layerbox中的顺序,最后加的在最上面,也可以调整顺序(databox中的move*方法)。

我使用了network.zoomOverview();
在添加一个lay1之后,var lay1:ILayer=new Layer(lay1);
当window大小变化时,不能像未添加时那般,network大小随着window按比例随之变化,而是出现滚动条。这个怎么办?
view plaincopy to clipboardprint?
代码: 
network.addEventListener(ResizeEvent.RESIZE,function(e:ResizeEvent):void{ 
                  network.zoomOverview(); 
               }); 

我的是这样,我把程序简化一下,其中的a.jpg就是个普通图片。代码运行后,zoomoverview不能达到理想效果。
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
            xmlns:twaver="http://www.servasoftware.com/2009/twaver/flex" 
            xmlns:demo="demo.common.*"  
            creationComplete="initApp()" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle"> 
   <mx:Script> 
      <!--[CDATA[ 
         import flash.events.KeyboardEvent; 
         import flash.net.Socket; 
         import flash.utils.ByteArray; 
         import mx.controls.Alert; 
         import mx.events.ListEvent; 
         import mx.events.ResizeEvent; 
         import twaver.*; 
         import twaver.network.Network; 
         import twaver.network.layout.AutoLayouter; 
         private var timer:Timer = new Timer(1000); 
         private var A1x:int=190,A2x:int=290,A3x:int=190,A4x:int=245,A5x:int=345, 
            B1x:int=50,B2x:int=50,B3x:int=200,B4x:int=200,B5x:int=400,B6x:int=600,B7x:int=600,B8x:int=800,B9x:int=800,B10x:int=1000,B11x:int=1000, 
            C1x:int=300,C2x:int=335,C3x:int=370,C4x:int=410,C5x:int=460, 
            D1x:int=92, D2x:int=65, D3x:int=120,D4x:int=190,D5x:int=167,D6x:int=220, 
            A1y:int=35, A2y:int=35, A3y:int=110,A4y:int=110,A5y:int=110, 
            B1y:int=150,B2y:int=250,B3y:int=150,B4y:int=250,B5y:int=250,B6y:int=200,B7y:int=300,B8y:int=150,B9y:int=350,B10y:int=100,B11y:int=400, 
            C1y:int=323,C2y:int=292,C3y:int=250,C4y:int=310,C5y:int=260, 
            D1y:int=180,D2y:int=255,D3y:int=255,D4y:int=180,D5y:int=255,D6y:int=255; 
          
         private var layerBox:LayerBox; 
          
         [Embed(source="a.jpg")] 
         public static const imageName:Class; 
         private var boxA:ElementBox,boxB:ElementBox,boxC:ElementBox,boxD:ElementBox,box:ElementBox ;//box不能在此处实例化 
         private function initApp():void{ 
            Utils.registerImageByClass("a",imageName); 
            boxB = networkB.elementBox; 
            layerBox = boxB.layerBox; 
             
            var lay1:ILayer=new Layer(lay1); 
            var lay2:ILayer=new Layer(lay2); 
            var B1:Node = createNode_B("B1",B1x,B1y); 
            var B2:Node = createNode_B("B2",B2x,B2y); 
            var B3:Node = createNode_B("B3",B3x,B3y); 
            var B4:Node = createNode_B("B4",B4x,B4y); 
            var B5:Node = createNode_B("B5",B5x,B5y); 
            var B6:Node = createNode_B("B6",B6x,B6y); 
            var B7:Node = createNode_B("B7",B7x,B7y); 
            var B8:Node = createNode_B("B8",B8x,B8y); 
            var B9:Node = createNode_B("B9",B9x,B9y); 
            var B10:Node= createNode_B("B10",B10x,B10y); 
            var B11:Node= createNode_B("B11",B11x,B11y); 
            B1.image="a"; 
            lay1.addChild(B1); 
            lay2.addChild(B2); 
             
            //layerBox.add(lay2); 
             
            //layerBox.add(lay1); 
            //layerBox.moveToBottom(lay1); 
             
         } 
         private function createNode_B(name:String,x:int,y:int):Node{ 
            var node:Node = new Node(); 
            node.name = name; 
            node.setLocation(x,y); 
            boxB.add(node); 
            return node; 
         } 
         private function networkZoomOverview(evt:ResizeEvent):void{ 
            networkA.zoomOverview(); 
            networkB.zoomOverview(); 
         } 
          
      ]]--> 
       
   </mx:Script> 
   <mx:states> 
      <mx:State name="C"> 
         <mx:SetProperty target="{windowC}" name="width" value="800"/> 
         <mx:SetProperty target="{windowC}" name="height" value="500"/> 
         <mx:SetProperty target="{windowB}" name="width" value="200"/> 
         <mx:SetProperty target="{windowB}" name="height" value="120"/> 
         <mx:SetProperty target="{windowC}" name="x" value="10"/> 
         <mx:SetProperty target="{windowC}" name="y" value="10"/> 
         <mx:SetProperty target="{windowB}" name="x" value="820"/> 
         <mx:SetProperty target="{windowB}" name="y" value="10"/> 
      </mx:State> 
      <mx:State name="B"> 
         <mx:SetProperty target="{windowC}" name="width" value="200"/> 
         <mx:SetProperty target="{windowC}" name="height" value="120"/> 
         <mx:SetProperty target="{windowB}" name="width" value="800"/> 
         <mx:SetProperty target="{windowB}" name="height" value="500"/> 
         <mx:SetProperty target="{windowB}" name="x" value="10"/> 
         <mx:SetProperty target="{windowB}" name="y" value="10"/> 
         <mx:SetProperty target="{windowC}" name="x" value="820"/> 
         <mx:SetProperty target="{windowC}" name="y" value="10"/> 
      </mx:State> 
   </mx:states> 
   <mx:transitions> 
      <mx:Transition fromState="*" toState="*"> 
         <mx:Parallel targets="{[windowC, windowB]}"> 
            <mx:Move /> 
            <mx:Resize /> 
         </mx:Parallel> 
      </mx:Transition> 
   </mx:transitions> 
   <mx:VBox width="100%" height="520" horizontalAlign="center" verticalAlign="middle"> 
      <mx:Canvas id="Canv" x="0" y="0" width="100%" height="100%"  >  
         <mx:TitleWindow x="40" y="40" width="200" height="50" layout="absolute" title="2" id="windowB" click="currentState='B'"  
                     headerHeight="12" creationCompleteEffect="sequenceEffect" rollOverEffect="glowUp" rollOutEffect="glowDown"> 
            <twaver:Network id="networkA" backgroundColor="0xADD8E6" width="100%" height="100%" fontSize="10"/> 
         </mx:TitleWindow> 
         <mx:TitleWindow x="40" y="40" width="200" height="50" layout="absolute" title="3" id="windowC" click="currentState='C'"  
                     headerHeight="12" creationCompleteEffect="sequenceEffect" rollOverEffect="glowUp" rollOutEffect="glowDown"> 
            <twaver:Network id="networkB" backgroundColor="0xADD8E6" width="300%" height="100%" fontSize="10" /> 
         </mx:TitleWindow> 
      </mx:Canvas > 
   </mx:VBox> 
</mx:Application> 

按你的代码,initApp()中添加:
代码:
networkB.addEventListener(ResizeEvent.RESIZE, networkZoomOverview);
呃,很抱歉,我犯了个低级失误,我简化代码时多删了下面这一段:
var link:Link = new Link(B1,B10);
link.setStyle(Styles.LINK_TYPE,Consts.LINK_TYPE_FLEXIONAL_HORIZONTAL);
boxB.add(link);
networkA.addEventListener(ResizeEvent.RESIZE,networkZoomOverview);
networkB.addEventListener(ResizeEvent.RESIZE,networkZoomOverview);
把上面这段添加到initApp()中后,运行完有滚动条。
我已经找到,问题出在link上,可能是因为B1与B10不在同一layer内吧。
具体解决方法,还请不吝赐教。。
Layer的使用有误,不是lay1.addChild(B1);
改用
代码:
var lay1:ILayer=new Layer(lay1);
            var lay2:ILayer=new Layer(lay2);
            layerBox.add(lay1);
            layerBox.add(lay2);
......
            B1.layerID = lay1.id;
            B2.layerID = lay2.id;

你可能感兴趣的:(.net,socket,Flash,UP)