A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] AS3 - Alpha Mask Help

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    27

    resolved [RESOLVED] AS3 - Alpha Mask Help

    Hi

    I have a startDrag function set up on a loader and mask that when the mouse is down on the loader it drags, when not it doesn't. There is also 2 buttons that control whether mask1 or mask2 is used.

    What i would like however is when the mouse is down - the area of the loader outside of the mask is visible but only by about 10/20% alpha, that way the user can see where all the image is while dragging. Is this possible?

    Full code can be seen below and i have attached the zip with the .fla file:

    Code:
    // Imports.
    import flash.display.Sprite;
    //
    
    // Sets masks as false on start up.
    maskP1.visible = false;
    maskP2.visible = false;
    //
    
    // Load External Image into loader.
    var imageP1:Loader = new Loader();
    var request:URLRequest = new URLRequest("image.jpg");
    imageP1.load(request);
    addChild(imageP1);
    imageP1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
    
    function onLoadComplete(event:Event):void {
    	imageP1.x = 67;
    	imageP1.y = 67;
    	imageP1.width = 425;
    	imageP1.height = 282;
    }
    //
    
    // Make Loader a Child of Sprite.
    var imageP1_Content:Sprite = new Sprite();
    imageP1_Content.buttonMode = true;
    imageP1_Content.addChild(imageP1);
    addChild(imageP1_Content);
    //
    
    // Set Drag Function.
    imageP1.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    imageP1.addEventListener(MouseEvent.MOUSE_UP, drop);
    
    function drag(event:Event):void {
      		imageP1_Content.startDrag();
    }
    function drop(event:Event):void {
      		imageP1_Content.stopDrag();
    }
    //
    
    // Set functions for mask scale.
    _10x10.addEventListener(MouseEvent.MOUSE_UP,scale1);
    _20x20.addEventListener(MouseEvent.MOUSE_UP,scale2);
    
    function scale1 (event:Event):void {
    	maskP1.visible = true;
    	maskP2.visible = false;
    	imageP1.mask = maskP1;
    }
    
    function scale2 (event:Event):void {
    	maskP2.visible = true;
    	maskP1.visible = false;
    	imageP1.mask = maskP2;
    }
    //
    Please, please help!

    Thanks in advance

    John
    Attached Files Attached Files
    Last edited by oddball25; 09-10-2010 at 11:15 AM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    // Imports.
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    //
    
    // Sets masks as false on start up.
    maskP1.visible=false;
    maskP2.visible=false;
    //
    
    // Load External Image into loader.
    var imageP1:Loader = new Loader();
    var request:URLRequest=new URLRequest("images/fire-color.png");
    imageP1.load(request);
    addChild(imageP1);
    imageP1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
    var imageA1:Bitmap;
    
    function onLoadComplete(event:Event):void {
    	imageA1=new Bitmap(Bitmap(imageP1.content).bitmapData.clone());
    	imageA1.alpha=0;
    	imageP1.x=imageA1.x=67;
    	imageP1.y=imageA1.y=67;
    	imageP1.width=imageA1.width=425;
    	imageP1.height=imageA1.height=282;
    	imageA1_Content.addChild(imageA1);
    }
    //
    
    // Make Loader a Child of Sprite.
    var image_Content:Sprite = new Sprite();
    var imageP1_Content:Sprite = new Sprite();
    var imageA1_Content:Sprite = new Sprite();
    image_Content.buttonMode=true;
    imageP1_Content.addChild(imageP1);
    image_Content.addChild(imageA1_Content);
    image_Content.addChild(imageP1_Content);
    addChild(image_Content);
    //
    
    // Set Drag Function.
    imageP1.addEventListener(MouseEvent.MOUSE_DOWN, drag);
    imageP1.addEventListener(MouseEvent.MOUSE_UP, drop);
    
    function drag(event:Event):void {
    	image_Content.startDrag();
    	imageA1.alpha=.2;
    }
    function drop(event:Event):void {
    	image_Content.stopDrag();
    	imageA1.alpha=0;
    }
    //
    
    // Set functions for mask scale.
    _10x10.addEventListener(MouseEvent.MOUSE_UP,scale1);
    _20x20.addEventListener(MouseEvent.MOUSE_UP,scale2);
    
    function scale1(event:Event):void {
    	maskP1.visible=true;
    	maskP2.visible=false;
    	imageP1.mask=maskP1;
    }
    
    function scale2(event:Event):void {
    	maskP2.visible=true;
    	maskP1.visible=false;
    	imageP1.mask=maskP2;
    }
    //

  3. #3
    Junior Member
    Join Date
    Jan 2010
    Posts
    27
    Wow, dawsonk thank you so much for the code to get this working

    A big thank you to helping me out with this one, appreciate it!

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