Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder Schrene's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    61
    Thanks
    12
    Thanked 1 Time in 1 Post

    Question AS3 Problems with removeChild

    I am new to Flash and still learning.
    I found this magnify code and tweaked it a bit.
    I wanted the magnifying glass to appear and work on the click of a button instead of automatically appearing as the code was designed.
    Here is the code:
    Code:
    var magPoint:Point = new Point(0, 0);
    
    var dMap:BitmapData = new BitmapData(colorMap_mc.width, colorMap_mc.height)
    dMap.draw(colorMap_mc)
    
    
    
    /// I was able to add the function to a button by adding this code
    goMagnify.addEventListener(MouseEvent.CLICK, magA);
    goMagnify.useHandCursor = true;
    function magA(e:MouseEvent):void{
    addChild(lens_mc);
    //////////// end of added code
    
    addChild(colorMap_mc);
    
    var magFilter:DisplacementMapFilter = new DisplacementMapFilter ();
    
    magFilter.scaleX 		= 50
    magFilter.scaleY 		= 50
    magFilter.componentX 	= 2
    magFilter.componentY 	= 4
    magFilter.mode		= "color" 
    magFilter.color		= 0x000000	
    magFilter.alpha 		= 0			
    magFilter.mapPoint	= magPoint;	
    magFilter.mapBitmap	= dMap;		
    
    scrollPane.filters = [magFilter]
    
    scrollPane.addEventListener(Event.ENTER_FRAME, onFrame)
    
    
    function onFrame(e:Event){
    	magPoint.x += ((mouseX-colorMap_mc.width -90)-magPoint.x)*0.3
    	magPoint.y += ((mouseY-colorMap_mc.height -80)-magPoint.y)*0.3
    	lens_mc.x = magPoint.x-19
    	lens_mc.y = magPoint.y+13
    	magFilter.mapPoint = magPoint
    	scrollPane.filters = [magFilter]
    
    }
    
    }
    //with this code I can only remove lens_mc the remove colorMap_mc does not work
    noMagnify.addEventListener(MouseEvent.CLICK, magB);
    noMagnify.useHandCursor = true;
    function magB(e:MouseEvent):void{
    addChild(lens_mc);///graphic
    removeChild(lens_mc);///graphic
    addChild(colorMap_mc);///magnifier 
    removeChild(colorMap_mc);///magnifier 
    
    }
    Here is the result:
    http://schrene.web44.net/zoom-text/zoomText.html

    with this I can get the graphic and the magnifier to appear but only the graphic to disappear.
    How can I get both to appear and disappear with the click of a button?? Any help would be greatly appreciated!
    Last edited by Schrene; 10-06-2011 at 07:44 PM. Reason: forgot sample link

  • #2
    New Coder Schrene's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    61
    Thanks
    12
    Thanked 1 Time in 1 Post

    Thumbs up I Found The Answer

    After much searching, trial, and error.....
    I found an answer that works!
    I realized it wasn't the child I was needing to remove but the BitmapData.
    I tried to remove it but couldn't find a method that worked.

    Here is what I did:
    Code:
    var magPoint:Point = new Point(0, 0);
    goMagnify.addEventListener(MouseEvent.CLICK, magA);
    goMagnify.useHandCursor = true;
    function magA(e:MouseEvent):void{
    var dMap:BitmapData = new BitmapData(colorMap_mc.width, colorMap_mc.height, true, 0x000000)
    dMap.draw(colorMap_mc)
    
    
    
    
    /// I was able to add this function to a button by adding this code
    
    //////////// end of added code
    addChild(colorMap_mc);
    addChild(lens_mc);
    
    
    
    var magFilter:DisplacementMapFilter = new DisplacementMapFilter ();
    
    magFilter.scaleX 		= 50
    magFilter.scaleY 		= 50
    magFilter.componentX 	= 1
    magFilter.componentY 	= 2
    magFilter.mode		= "color" 
    magFilter.color		= 0x000000	
    magFilter.alpha 		= 0			
    magFilter.mapPoint	= magPoint;	
    magFilter.mapBitmap	= dMap;		
    
    scrollPane.filters = [magFilter]
    
    scrollPane.addEventListener(Event.ENTER_FRAME, onFrame)
    
    
    function onFrame(e:Event){
    	magPoint.x += ((mouseX-colorMap_mc.width -90)-magPoint.x)*0.3
    	magPoint.y += ((mouseY-colorMap_mc.height -80)-magPoint.y)*0.3
    	lens_mc.x = magPoint.x-20
    	lens_mc.y = magPoint.y+13
    	magFilter.mapPoint = magPoint
    	scrollPane.filters = [magFilter]
    
    
    noMagnify.addEventListener(MouseEvent.CLICK, magB);
    noMagnify.useHandCursor = true;
    function magB(e:Event){
    addChild(lens_mc);///graphic
    removeChild(lens_mc);///graphic
    
    
    magFilter.scaleX 		= 0
    magFilter.scaleY 		= 0
    }
    }
    
    
    }


  •  

    Posting Permissions

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