A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] [F8] How to know which button was clicked?

  1. #1
    Senior Member FlashyGirl's Avatar
    Join Date
    May 2003
    Location
    Portugal
    Posts
    117

    [RESOLVED] [F8] How to know which button was clicked?

    I'm having a bit of a problem on getting to know what button was pressed, or at least convert that info into a number.
    Here's what I want to do:

    STAGE-------->fundo(movieclip)-------->botao(button)

    I have a for cycle displaying the fundo movieclip in rows and collumns, so that the images and text that are inside the fundo movieclip can repeat. But there's also a button so when I click, something different happens for each movieclip. The thing is that I want to be returned a number for each movieclip. All I got on trace untill now is "_level0.fnd6.botao", but the only info that I want is "fnd6", or only "6", if that's possible. Is there a way to get that?

    This is the button function:
    Code:
    linha.botao.onRelease = function(){
    	trace(this);
    	for (i=0; i<totalitems; i++){
    		//with this I remove all movieclips already on stage
    		_root["fnd"+i].removeMovieClip("fnd"+i);
    	}
    };

    And, if you need to check the rest of the code:
    Code:
    System.useCodepage = true;
    var MeuXML:XML = new XML();
    MeuXML.ignoreWhite = true;
    MeuXML.onLoad = function(sucesso)
    {
    		xpos = 20;
    		ypos = 20;
    		vspace = 26;
    		hspace = 46;
    		altura = 200;
    		largura = 160;
    		contlinhax = 0;
    		contlinhay =0;
    	
    	
    	if (sucesso)
    	{
    		totalitems = MeuXML.firstChild.childNodes.length;
    		for (i=0; i<totalitems; i++)
    			{
    				img = MeuXML.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
    				nomebaila = MeuXML.firstChild.childNodes[i].attributes.id;
    				linha = fundo.duplicateMovieClip("fnd"+i, _root.getNextHighestDepth());
    				linha.mcvazio.loadMovie(img, _root.getNextHighestDepth());
    				linha.nome.text = nomebaila;
    				linha.botao.onRelease = function(){
    					trace(this);
    					}
    				linha.botao.onRelease = function(){
    						trace(linha.nome.text);
    					for (i=0; i<totalitems; i++){
    						_root["fnd"+i].removeMovieClip("fnd"+i);
    						}
    					};
    				linha._x = (xpos-10)+((largura+hspace)*contlinhax);
    				contlinhax++;
    				linha._y = (ypos-10)+((altura+vspace)*contlinhay);
    				if (contlinhax == 5){
    					contlinhay++;
    					contlinhax = 0;
    				}
    			}
    		
    	}
    	else
    	{
    		trace(sucesso);
    		trace("Ocorreu um erro ao carregar os dados.");
    	}
    };
    MeuXML.load("bailar.xml");
    stop();
    Last edited by FlashyGirl; 03-27-2007 at 10:19 AM.

  2. #2
    Senior Member FlashyGirl's Avatar
    Join Date
    May 2003
    Location
    Portugal
    Posts
    117
    I don't want to believe that no one knows this...

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    linha.botao.id = i;

    linha.botao.onRelease = function(){
    trace("you clicked button " + this.id);
    for (i=0; i<totalitems; i++){
    //with this I remove all movieclips already on stage
    _root["fnd"+i].removeMovieClip("fnd"+i);
    }
    };
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member FlashyGirl's Avatar
    Join Date
    May 2003
    Location
    Portugal
    Posts
    117
    Like clockworks! Perfect! Thank you so much!

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    yw
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center