Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Eventi menu drop down

  1. #1

    Eventi menu drop down

    Ciao.
    Sto a diventar matto sto cercando di costruirmi
    le basi per un menu drop down
    il down lo vorrei fare in orizzontale invece che verticale,
    e mi trovo in un bel pasticcio bando alle ciance il codice
    è un po lungo ma di facile interpretazione
    Codice PHP:
    package com.w.data
        
    import flash.events.Event
        
    import flash.events.IOErrorEvent
        
    import flash.events.ErrorEvent
        
    import flash.net.URLLoader
        
    import flash.net.URLRequest

        public class 
    MenuTree extends URLLoader
            public static const 
    ON_COMPLETE_MENU        String "onCompleteMenu"
            private var 
    xmlLoader:URLLoader
            private var 
    _xml:XML
            private var 
    _items:Array = []; 
            private var 
    _itemDefaultAttive:uint
            public function 
    MenuTree() { 
                
    xmlLoader = new URLLoader(); 
                
    xmlLoader.addEventListener(Event.INITonLoadXml); 
                
    xmlLoader.addEventListener(Event.COMPLETEparseXML); 
                
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,onLoadXmlError); 
                
    xmlLoader.load(new URLRequest("data/menu.xml")); 
            } 
            private function 
    onLoadXml(event:ErrorEvent):void {} 
            private function 
    onLoadXmlError(event:ErrorEvent):void 
                
    trace("cannot load xml file"); 
            } 
            private function 
    parseXML(event:Event):void 
                var 
    loader:URLLoaderevent.target as URLLoader
                
    _xml =new XML(loader.data); 
                
    _xml.ignoreWhitespace=true
                for 
    each (var node:XML in _xml.menu) { 
                    var 
    item:Object = {}; 
                    
    item.label node.@label
                    
    item.href node.@href
                    
    item.name node.@name
                    
    item.subItem = []; 
                    for 
    each (var subnode:XML in node.submenu) { 
                        var 
    subItem:Object = {}; 
                        
    subItem.label subnode.@label
                        
    subItem.href subnode.@href
                        
    subItem.name subnode.@name
                        
    item.subItem.push(subItem); 
                    } 
                    
    _items.push(item); 
                } 
                
    _itemDefaultAttive_xml.navigation.@itemDefaultAttive;//get item for active.*/ 
                
    dispatchEvent(new Event(ON_COMPLETE_MENU)); 
            } 
             
             
            public function 
    get items():Array { 
                return 
    _items 
            

            public function 
    get defaultAttive():uint 
                return 
    _itemDefaultAttive
            } 
        } 


    package com
        
    import flash.display.Sprite
        
    import flash.events.Event
        
    import flash.events.MouseEvent
        
    import com.w.data.MenuTree
        public class 
    Main extends Sprite 
            private var 
    menuTree:MenuTree
            public function 
    Main() { 
                
    menuTree = new MenuTree(); 
                
    menuTree.addEventListener(MenuTree.ON_COMPLETE_MENUinit); 
            } 

            private function 
    init(event:Event):void 
                
    menuTree.removeEventListener(MenuTree.ON_COMPLETE_MENUinit); 
                var 
    xPos:Number=0
                var 
    space:Number=1
                var 
    container:Sprite=new Sprite(); 
                for 
    each (var item:Object in menuTree.items) { 
                    var 
    tab:Tab = new Tab(); 
                    
    tab.buttonMode=true
                    
    tab.name=item.name
                    
    tab.href=item.href
                    
    tab.label_txt.text=item.label
                    
    tab.label_txt.selectable=false
                    
    tab.label_txt.mouseEnabled=false
                    
    tab.x=xPos
                    
    xPos+=space
                    
    xPos+=tab.width
                    var 
    containerSub:Sprite=new Sprite(); 
                    
    containerSub.y=tab.height
                    
    containerSub.visible=false
                    
    containerSub.name=item.name
                    var 
    xSubPos:Number=0
                    
    containerSub.x=0
                    var 
    count:uint 0
                    for 
    each (var subItem:Object in item.subItem) { 
                        var 
    subTab:SubTab = new SubTab(); 
                        
    subTab.buttonMode=true
                        
    subTab.x=xSubPos
                        
    xSubPos+=subTab.width
                        
    subTab.name=subItem.name
                        
    subTab.href=subItem.href
                        
    subTab.label_txt.text=subItem.label
                        
    subTab.label_txt.selectable=false
                        
    subTab.label_txt.mouseEnabled=false
                        
    containerSub.addChild(subTab); 
                        
    count++; 
                    } 
                    
    //containerSub.x=-xSubPos/count; 
                    
    containerSub.graphics.beginFill(0x0000000); 
                    
    containerSub.graphics.drawRect(00containerSub.width 1containerSub.height 1); 
                    
    containerSub.graphics.endFill(); 
                    
    tab.addChild(containerSub); 
                    
    container.addChild(tab); 
                    
    //tab.addEventListener(MouseEvent.ROLL_OVER, _rollOverHandler); 
                    //tab.addEventListener(MouseEvent.ROLL_OUT, _rollOutHandler); 
                    //tab.addEventListener(MouseEvent.CLICK, _mouseClickHandler); 

                

                
    trace(container.width);  
                
    /* restituisce -107373698.4 ?????? 
                 se tolgo containerSub.x=-xSubPos/count; 
                 mi restituisce 604 invece secondo me  
                 dovrebbe essere (120+1)*4 
                */ 
                
    addChild(container); 
                 
                
    container.addEventListener(MouseEvent.ROLL_OVER_rollOverHandler); 
                 
            } 
             
            private function 
    _rollOverHandler(event:MouseEvent):void 
                
    //event.currentTarget.getChildAt(2).visible=true; 
                
    trace(event.currentTarget); // Sprite
                
    trace(event.target); 
                 
            } 
            private function 
    _rollOutHandler(event:MouseEvent):void 
                 
    //event.currentTarget.getChildAt(2).visible=false; 
            

            private function 
    _mouseClickHandler(event:MouseEvent):void 
                
    //trace(event.target.href); 
            

        } 


    Brevemente quello che cerco di fare
    metto in uno Sprite tutte le tab e questo
    è il container per il primo livello
    fatto questo gli assegno un addEventListener
    su mouse hover
    (fatto questo mi aspetterei che quando clicco su tab
    il target fosse container e il currentTarget il tab).

    Al clic sul tab mi servono
    width del container
    width del subContainer
    e proprietà del Tab.

    I problemi sono nei commenti
    e sopratutto il non riuscire a gestire
    target e currentTarget



    Con containerSub.x=-xSubPos/count;
    cerco di centrare il submenu.

    Spero di essermi spiegato.
    In caso chiedete.


    Ciao
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  2. #2
    Il problema era ROLL_OVER
    Adesso useCapture è settato a true
    Questa è un test di debug

    a cui ho tolto subContainer
    ()
    Codice PHP:
    private function init(event:Event):void {
                
    menuTree.removeEventListener(MenuTree.ON_COMPLETE_MENUinit);
                var 
    xPos:Number=0;
                var 
    space:Number=1;
                var 
    container:Sprite=new Sprite();
                
    container.name="container";
                
    container.graphics.beginFill(0x000000);
                
                
    //container.mouseChildren=false; 
                
    for each (var item:Object in menuTree.items) {
                    var 
    tab:Tab = new Tab();
                    
    tab.mouseChildren false;
                    
    tab.buttonMode=true;
                    
    tab.name=item.name;
                    
    tab.href=item.href;
                    
    tab.label_txt.text=item.label;
                    
    tab.label_txt.selectable=false;
                    
    tab.label_txt.mouseEnabled=false;
                    
    tab.x=xPos;
                    
    xPos+=space;
                    
    xPos+=tab.width;
                    
    container.addChild(tab);
                }
                
    container.graphics.drawRoundRect00container.widthcontainer.height2);
                
    container.graphics.endFill();
                
    addChild(container);
                
    container.addEventListener(MouseEvent.ROLL_OVER_rollOverHandlertrue);
            }
            
            private function 
    _rollOverHandler(event:MouseEvent):void {
                
    //event.currentTarget.getChildAt(2).visible=true;
                
    trace(event.currentTarget.name);
                
    trace(event.target.name);
                
            } 

    Secondo voi è il modo giusto ?
    Esistono altri modi ?
    Il link che mi ha chiarito le idee
    http://www.zedia.net/2008/difference...e_over-in-as3/

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.