Bach 0 Denunciar post Postado Fevereiro 6, 2010 ea galera, preciso fazer um menu drop down dinamico as3 com xml alguem pode me dar uma dica de como faze? grato Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 6, 2010 Vai depender um pouco de qual o seu nível de conhecimento/experiencia com o AS3. Primeiro, você já consegue ler seu xml externo, e acessar os dados que você quer? Segundo passo, é 'montar' o seu menu, usando loops de acordo com a quantidade de itens de cada menu/sub menu. Pra isso, você precisa conhecer razoavelmente como manipular a Display List. Agora, você vai usar eventos para controlar o comportamento do seu DropDown. Em uma busca rápida achei duas classes, que talvez ajudem: http://www.christeso.com/blog/index.php/lab/as3-drop-down-menu-class/ http://www.terrypaton.com/as3-simple-drop-down-menu/ não testei, e não faço ideia se funcionam, mas pode te ajudar... boa sorte =) Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 6, 2010 Michel muito obrigado pelas dicas vo da uma olhada nelas que com certeza vai me ajudar sim e se mais alguem poder me dar mais dicas eu agradeço! Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 9, 2010 tudo bem pessoal? alguem pode me da uma forcinha pra resolver esse probleminha ainda nao conheço muito as3! peguei essa clase na net pra utilizar no meu site e esta mostrando os seguintes erros nas linhas mostradas em vermelho 1120: Access of undefined property thisObj. 1067: Implicit coercion of a value of type XmlMenu to an unrelated type Function. package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.net.URLLoader; import flash.net.URLRequest; public class XmlMenu { private var menu_xml:XML; private var m_parent_mc:MovieClip; private var m_menu_array:Array; public function XmlMenu(xmlpath_str:String, parent_mc:MovieClip) { this.m_parent_mc = parent_mc; this.m_menu_array = new Array(); // call this class' initXML function which parses your XML navigation file. initXML(xmlpath_str); } // define your function which will be triggered when the XML file has completed loading. private function completeHandler(event:Event):void { menu_xml = XML(event.currentTarget.data); var menuXMLList:XMLList = menu_xml.menu; var nodeXML:XML; // create an array which contains the main navigation as well as each menu's sub-navigation links. var menu_array:Array = new Array(); // if the XML file was successfully loaded and parsed, // convert it into an array of objects which we can pass to the XmlMenu class' initMenu method. var i:Number; // for each child node in the XML file (the child nodes here are the main menu navigation items. for each (nodeXML in menuXMLList) { // create an empty array for sub-navigation items. var submenu_array:Array = new Array(); // for each child node of the main menu items, append the values to our submenu_array. var subNodeXML:XML; for each (subNodeXML in nodeXML.children()) { // append each sub-navigation item to our submenu_array Array. // Our XML file specifies the navigation's label and url in attributes rather than child nodes, // so if you modify the layout of the navigation XML file this code will need to be modified. submenu_array.push({caption:subNodeXML.@name, href:subNodeXML.@href}); } // append each menu items, and it's array of submenu items. menu_array.push({caption:nodeXML.@name, href:nodeXML.@href, subnav_array:submenu_array}); } // call the XmlMenu class' initMenu method. initMenu(menu_array); } // This function, initXML, takes a single parameter (xmlpath_str) and is responsible for // loading and parsing the XML document and converting it into an array of objects. private function initXML(xmlpath_str:String):void { // The XML object which you will use to load and parse the XML navigation file. menu_xml = new XML(); menu_xml.ignoreWhitespace = true; var xmlLdr:URLLoader = new URLLoader(); xmlLdr.addEventListener(Event.COMPLETE, completeHandler); // load the navigation XML file. xmlLdr.load(new URLRequest(xmlpath_str)); } // this method, initMenu, loops through the menu items and their respective // sub navigation items and builds the movie clips. private function initMenu(nav_array:Array):void { // create variables which we will use to position the menu items. var thisX:Number = 20; var thisY:Number = 20; var menuIndex:Number; for (menuIndex = 0; menuIndex < nav_array.length; menuIndex++) { // for each main menu item attach the menu_mc symbol from the library and position it along the x-axis. var menuMC = new menu_mc(); menuMC.buttonMode = true; m_parent_mc.addChild(menuMC); menuMC.x = thisX; menuMC.y = thisY; // store the current menu item's information within the MovieClip so you // always have a reference to the sub navigation and the current menu item's link menuMC.data = nav_array[menuIndex]; // add a reference to the current menu movie clip in the class' m_menu_array Array. m_menu_array.push(menuMC); // set the caption on the main menu button. menuMC.label_txt.text = menuMC.data.caption; menuMC.label_txt.selectable = false; menuMC.label_txt.mouseEnabled = false; // create a new movie clip on the Stage which will be used to hold the submenu items. var subMC:MovieClip = new MovieClip(); //subMC.buttonMode = true; m_parent_mc.addChild(subMC); // set the sub menu's X and Y position on the Stage. subMC.x = thisX; subMC.y = menuMC.height; // set a variable in the submenu movie clip which stores whether the current sub menu item is visible subMC.subMenuVisible = true; // call the hideSubMenu method which hides the sub menu item. hideSubMenu(subMC); // within the sub menu movie clip store a reference to the menu movie clip subMC.parentMenu = menuMC; // hide the sub menu movie clip on the Stage. subMC.visible = false; // set a variable which we will use to track the current y-position of the sub-navigation items. var yPos:Number = thisY; var temp_subnav_array:Array = menuMC.data.subnav_array; // for each sub menu item, attach a new instance of the link_mc MovieClip from the Library, // set the text for the link and increment the yPos counter. var i:Number; for (i = 0; i < temp_subnav_array.length; i++) { var linkMC:MovieClip = new link_mc(); linkMC.buttonMode = true; subMC.addChild(linkMC); linkMC.x = 0; linkMC.y = yPos; linkMC.data = temp_subnav_array[i]; linkMC.label_txt.text = linkMC.data.caption; linkMC.label_txt.mouseEnabled = false; linkMC.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); yPos += linkMC.height; } // draw a slight 1 pixel drop shadow around the sub menu using the drawing API var thisWidth:Number = subMC.width + 1; var thisHeight:Number = subMC.height + 1; subMC.graphics.beginFill(0x000000, 0); subMC.graphics.moveTo(0, 0); subMC.graphics.drawRect(0, 0, thisWidth, thisHeight); subMC.graphics.endFill(); // menuMC.childMenu = subMC; thisX += menuMC.width; } // define the onRollOver and onRelease for each main menu item. for (var j:int = 0; j < this.m_menu_array.length; j++){ var thisMenuItem:MovieClip = m_menu_array[j]; thisMenuItem.buttonMode = true; thisMenuItem.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler); thisMenuItem.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); } } private function rollOverHandler(event:MouseEvent):void { showSubMenu(event.currentTarget.childMenu); } private function mouseUpHandler(event:MouseEvent):void { trace(event.currentTarget.data.href); } // the showSubMenu method displays the specified sub menu movie clip private function showSubMenu(target_mc:MovieClip):void { // create a reference to the current class. var thisObj = this; if (!target_mc.subMenuVisible) { hideAllSubMenus(); target_mc.visible = true; target_mc.subMenuVisible = true; target_mc.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } } private function mouseMoveHandler(event:MouseEvent):void { var thisMC:MovieClip = event.currentTarget as MovieClip; // hit test both the main menu item, and the submenu to see if the mouse is over either one of them. var subHit:Boolean = thisMC.hitTestPoint(event.stageX, event.stageY, true); var menuHit:Boolean = thisMC.parentMenu.hitTestPoint(event.stageX, event.stageY, true); // if the mouse is not over the main menu or sub menu, // hide the submenu movie clip and delete the onMouseMove event listener since we don't need it any more. /////////////////////////////////////// Nesta parte /////////////////////////////////////////////// if (!((subHit || menuHit) && thisMC.subMenuVisible)) { thisObj.hideSubMenu(thisMC); thisMC.removeEventListener(event.type,this); } ////////////////////////////////////////////////////////////////////////////////////////////////// } // hide the specified sub menu Movie Clip, if it is visible. private function hideSubMenu(target_mc:MovieClip):void { if (target_mc.subMenuVisible) { target_mc.visible = false; target_mc.subMenuVisible = false; } } // hide the sub menu for each menu item in the m_menu_array Array. private function hideAllSubMenus():void { for (var i:int = 0; i < this.m_menu_array.length; i++){ hideSubMenu(this.m_menu_array[i].childMenu); } } // toggle a specific menu's visibility. private function toggleSubMenu(target_mc:MovieClip):void { (target_mc.subMenuVisible) ? hideSubMenu(target_mc) : showSubMenu(target_mc); } } } Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 9, 2010 Olá Bach, no momento não posso compilar todo o código pra ver se vai tudo ok (em ambiente linux sem sdk), mas quanto aos dois erros que você falou é o seguinte: 1120: Access of undefined property thisObj. veja que a variável thisObj está sendo declarada dentro da função showSubMenu, o que faz dela uma variável de escopo local (só pode ser acessada dentro dessa função). Por isso o erro. Uma solução pode ser você declará-la fora da função, lá no inicio da classe (onde estão sendo declaradas as variáveis privadas) da seguinte forma: private var thisObj:XmlMenu; aí dentro da função showSubMenu você retira a declaração de variável, fazendo com que a linha: var thisObj = this; fique simplesmente assim: thisObj = this; quanto ao segundo erro: 1067: Implicit coercion of a value of type XmlMenu to an unrelated type Function. troque a linha: thisMC.removeEventListener(event.type,this); por: thisMC.removeEventListener(event.type, mouseMoveHandler); o this dentro de uma classe se refere ao objeto instanciado dessa classe, mesmo estando dentro de uma função. agora testa aí, vê se n aparece mais nenhum erro =) []'s Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 9, 2010 Olá Michel muito obrigado pela ajuda que esta me dando, so que agora mostra este erro: Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///D|/web%5Fsites/imob/flash/site/menu.xml at XmlMenu/initXML() at XmlMenu() at index_fla::MainTimeline/frame2() no meu flash estou recuperando assim new XmlMenu("menu.xml", this); Compartilhar este post Link para o post Compartilhar em outros sites
Matheus Brito 12 Denunciar post Postado Fevereiro 9, 2010 Ele não ta conseguindo abrir a stream. Verifique os caminhos. Abs Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 10, 2010 Obrigado corrigi o caminho. Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 10, 2010 beleza galera novamente preciso de ajuda como faço para adicionar ações no menu tipo quando eu clicar num link adiciona um mc no palco quando eu clicar em outro adcionar outro e quando eu clicar num terceiro link vai pra outro site ainda não consigo meche na classe. Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 11, 2010 tudo vai estar na função mouseUpHandler. no xml, cada botão tem um nó href certo? Veja que na função ele está dando um trace nesse dado. Para navegar, basta você colocar um navigateToURL ali, usando esse dado. Agora, se é pra cada botão ter um comportamento diferente (um chama MC, outro navega pra outra página), você vai precisar criar um atributo ou nó no xml que indique qual ação deverá ser tomada. Aí dentro da função mouseUP você põe um condicional com esse dado, direcionando ou pro navigateToURL (se for pra navegar pra outra pagina), ou pra um Loader e addChild (se for pra carregar um arquivo externo e adiciona-lo ao palco). Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 18, 2010 Estou com problema para add um arquivo externo no palco mostra esse erro 1061: Call to a possibly undefined method addChild through a reference with static type Class. private function mouseUpHandler(event:MouseEvent):void { var arquivo = event.currentTarget.data.acao; var L_arquivo:Loader = new Loader(); var endereco:URLRequest = new URLRequest(arquivo); L_arquivo.load(endereco); //adiciona o swf ao palco palco_mc.addChild(arquivo); } No xml tá assim: <menu name="Empresa" acao="empresa.swf" /> Fiz assim private function mouseUpHandler(event:MouseEvent):void { var L_arquivo:Loader = new Loader(); var endereco:URLRequest = new URLRequest("empresa.swf"); L_arquivo.load(endereco); //adiciona o swf ao palco palco_mc.addChild(L_arquivo); } continua o mesmo erro: 1061: Call to a possibly undefined method addChild through a reference with static type Class. e se eu tiro palco_mc não mostra erro mas também não aparece nada alguem pode me ajudar a resolver Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 20, 2010 o primeiro código creio que você já sabe o que estava errado, tanto que concertou... quanto ao segundo... quem é palco_mc? Dei uma olhada e não o achei e nenhuma outra parte do seu código. []'s Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 20, 2010 Olá Michel beleza palco_mc é um MovieClip que eu criei coloquei no palco e instanciei como palco_mc porem mesmo eu tirando isso da classe deixando addChid(L_arquivo); e deletando esse mc, quando eu clico no botao do menu nao aparece nada, nem erro nem carrega o arquivo externo, ficando na tela somente o menu. Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 22, 2010 estranho... você instanciou o MC como palco_mc ou marcou o movieclip para ser exportado para o ActionScript? Por que ele está interpretando o palco_mc como um objeto Class e não um MovieClip. Se vai usar uma vez e coloca-lo no palco, não precisa exporta-lo para o ActionScript, e sim colocar o nome no Instance Name. Se não resolver, e puder postar o arquivo, fica mais fácil []'s Compartilhar este post Link para o post Compartilhar em outros sites
Bach 0 Denunciar post Postado Fevereiro 24, 2010 Ufa... um dos problemas esta resolvido eu tava chamando a classe lá no meu frame assim: new XmlMenu("menu.xml", this); e agora eu coloquei assim: palco_mc.addChild(new XmlMenu("menu.xml", this)); e esta carregando, so que quando eu clico em outro botao ele carrega por cima do que ja esta no palco , como eu faço pra remover o que carrego antes de carregar o proximo? Compartilhar este post Link para o post Compartilhar em outros sites
Michel Araújo 0 Denunciar post Postado Fevereiro 24, 2010 Sua classe não está extendendo nenhum tipo de DisplayObject O_o Pelo menos não a q você postou =) Maaas... estando o objeto dela no palco, para remove-lo primeiro você precisa apontar uma variável para ele, para que você possa se referir a esse objeto mais tarde: var meuXmlMenu:XmlMenu = new XmlMenu("menu.xml", this); palco_mc.addChild(meuXmlMenu); agora quando você precisar removê-lo do palco, basta dar um palco_mc.removeChild(meuXmlMenu); depois você pode apontar essa variável pra outro objeto XmlMenu, e coloca-lo no palco =) Compartilhar este post Link para o post Compartilhar em outros sites