A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: MouseEvent.CLICK Problem

  1. #1
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103

    MouseEvent.CLICK Problem

    Is there any reason why a MouseEvent.CLICK would affect only 1 of 5 items, whereas a MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT affect 5 of 5 items when each event listener is applied exactly the same way?

    For some reason, of the 5 images I've imported, only the last image is able to be clicked and have click actions applied, yet it is able to receive the ROLL_OVER and ROLL_OUT messages. So that leaves me thoroughly confused.

    Here is the code I'm using, I'd greatly appreciate your help ---

    Code:
    import XMLManager;
    import caurina.transitions.Tweener;
    import MakeHand;
    
    var images:XMLList;
    var box:Sprite;
    var boxes:Array = [];
    var loadedImages:Number = 0;
    
    var imageList:XMLManager = new XMLManager("images.xml");
    imageList.addEventListener(Event.COMPLETE, formatXMLContent);
    imageList.start();
    
    function formatXMLContent(event:Event):void {
    	images = imageList.xmlContent.images.image;
    	
    	for (var i:uint = 0; i < images.length(); i++) {
    		var loadedImages:Number = 0;
    		var loader:Loader = new Loader();
    		var urlRequest:URLRequest = new URLRequest(images[i]);
    		
    		box = new Sprite();
    		box.graphics.beginFill(0xFFFFFF, 0);
    		box.graphics.drawRect(-50, -50, 125, 195);
    		box.graphics.endFill();
    		box.x = i * box.width; box.y = 150;
    		box.addEventListener(MouseEvent.CLICK, clickOn);
    		box.addEventListener(MouseEvent.ROLL_OVER, rollOn);
    		box.addEventListener(MouseEvent.ROLL_OUT, rollOff);
    		addChild(box);
    		
    		// trace(getChildIndex(box)); // 0, 1, 2, 3, 4
    		
    		boxes.push(box);
    		boxes[i].x += stage.stageWidth / 6;
    		loader.load(urlRequest);
    		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
    	}
    }
    
    function imageLoaded(e:Event):void {
    	var image:Bitmap = (Bitmap)(e.target.content);
    	image.x = -50;
    	image.y = -50;
    	var holder:Sprite = boxes[loadedImages];
    	holder.addChild(image);
    	loadedImages++;
    }
    
    function clickOn(e:Event):void {
    	setChildIndex(e.target as Sprite, numChildren - 1); 
    	Tweener.addTween(e.target, {scaleY: 1.5, scaleX: 1.5, time: .4, transition: "easeOutExpo"});
    	box.removeEventListener(MouseEvent.ROLL_OVER, rollOn);
    	box.removeEventListener(MouseEvent.ROLL_OUT, rollOff);
    }
    
    function rollOn(e:Event):void {
    	setChildIndex(e.target as Sprite, numChildren - 1); 
    	Tweener.addTween(e.target, {scaleY: 1.5, scaleX: 1.5, time: .4, transition: "easeOutExpo"});
    }
    
    function rollOff(e:Event):void {
    	Tweener.addTween(e.target, {scaleY: 1, scaleX: 1, time: .3, transition:"easeOutExpo"});
    }
    I left the code somewhat full as the problem could be anywhere! I just don't get it.

    Thanks -

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Any chance these are tabs that overlap eachother with transparent pixels?
    Please use [php] or [code] tags, and mark your threads resolved 8)

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    No I don't think so because they're spaced out by i * box.width.

    Also, each receives the ROLL/ROLL OFF instruction.

    ...not sure how else transparent pixels would happen nor how the code is doing it.


  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Replace target with currentTarget. Just a trial.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    Replace target with currentTarget. Just a trial.
    Nope same affect. Bloody.

    Thanks though -

  6. #6
    Senior Member
    Join Date
    Apr 2002
    Location
    Atlanta
    Posts
    103
    Wow, what I love is I can give each item a name and then trace the event & what I'm clicking on and they both appear for every image... yet only 1 works.

    I mean I'm sure Adobe isn't out to get me or anything.

  7. #7
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    try not declaring box , outside your additems function. I dont know if thats the exact cause of your problems , but it would seem like it would be. You should be declaring it as a local var to that method , seeing as you push each new instance into an array for reference later. If you think about it your basically adding an event listener to box , then adding it again , then again , then again. So the only listener that does not get an override will be the one added in the last iteration of your loop. Probably the reason why only one of your buttons works. So try removing that declaration from up at the top , and add it to your for loop :


    var box : Sprite = new Sprite();

    In your other functions , where you directly reference box , instead of just saying , box , say , evt.target.removeEventListener .. etc.
    Last edited by AttackRabbit; 10-30-2009 at 07:13 AM.

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