dcsimg
A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: dynamic instances names

  1. #21
    Flash Your Flex
    Join Date
    Apr 2007
    Location
    Provo, Utah
    Posts
    45
    clip is reset every loop of the for statement. So clip is a temp var that holds whatever clip we are working with. By clip.i = i we assign that clip a static, non changing index number that we are referencing from the for loop.

    when we get a e.target call that references whatever has been clicked. and since we have already assigned to it the clip (via clip.i = i) as a static var then we can reference it by saying e.target.i

  2. #22
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    I think i got it now
    i is just i, nothing more, i was thinking it had something to do with the another i variable inside the loop
    Its simple but sometimes i get confused with names that looks the same somehow, thanks!

  3. #23
    Flash Your Flex
    Join Date
    Apr 2007
    Location
    Provo, Utah
    Posts
    45
    yup! Sorry, I just realized my response was very convoluted!

  4. #24
    Junior Member
    Join Date
    May 2007
    Posts
    12
    hi everybody.....still got some problem here!!!!

    the code is:

    Code:
    function completeHandler(event:Event):void
    	{
    	var dataXML:XML = XML(event.target.data);
    	//trace(dataXML.toXMLString());
    	//trace(dataXML.item[0].nome);
    	var numeroClienti:int = dataXML.item[0].quantita;
    	var posIniziale:Number = 0;
    	var totalClients:int = 10;
    	var clients:Array = new Array();
    	var nomiClienti:Array = new Array();
    	for (var a:int = 1 ; a <= totalClients ; a++ ) {
    		nomiClienti.push(dataXML.item[a].nome);
    	}
    	//trace(nomiClienti);
    	for (var i:int = 1 ; i < totalClients ; i++) {
    		var clip:MovieClip = new MovieClip();
    		var nomeCliente:String = nomiClienti[i];
    		var labelNome:Label = new Label();
    		labelNome.text = nomeCliente;
    		labelNome.autoSize = TextFieldAutoSize.LEFT;
    		clip.addChild(labelNome);
    		//clip.addChild(rattangolo);
    		clip.name = "cliente" + i;
    		clip.y = posIniziale;
    		clip.num = i;
    		clients.push(clip);
    		addChild(clip);
    		clip.addEventListener(MouseEvent.CLICK, handleMouseClick);
    		posIniziale += 18;
    	}
    	function handleMouseClick(e:Event){
    		trace(e.target.num);
    	}
    }
    I modified the malihk code for the movieclip to display a label instead of a simple shape....

    The problem is that the label get priority over the eventListener for the mouse clic...in fact when I clic on a clip created, the compiler says that the num property (associated to the movie clip with: clip.num = i is "impossible to find on flash.text.TextField" and not on the movieclip.....
    Is there a way to bypass this problem????

    Thanks...

  5. #25
    Junior Member
    Join Date
    May 2007
    Posts
    12
    I just solved the problem placing a transparent shape inside a movie, and adding it at the same level of the textfield. So I attached the variable to this movie and all is ok...

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