Search code examples
actionscript-3flashflash-builderstage3d

Cannot mask Stage3D SWF in Loader


Working in FlashBuilder, I build a mobile AS3 application that uses a Loader to display a local SWF file. It masks the loader so it only shows a 640x480 window. This worked fine using an old SWF file (a Flixel game, non-Stage3D).

I then tried it with a Stage3D-enabled SWF file. This failed to run, because the application was not set to run in the 'direct' renderMode (it had been in auto up until this point). This allowed the application to run, but the SWF file now ignores the Loader's mask and displays across the entire stage.

Is it not possible to mask Stage3D SWFs when loaded in this way? The loading looks like so:

        public function FlixelTest()
    {
        super();

        stage.align = StageAlign.TOP_LEFT;
        stage.scaleMode = StageScaleMode.NO_SCALE;
        Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

        myLoader.x = (stage.fullScreenWidth-640)/2;
        myLoader.y = (stage.fullScreenHeight-480)/2;

        var url:URLRequest = new URLRequest("stage3dswf.swf"); // in this case both SWFs are in the same folder
        myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
        myLoader.load(url);    // load the SWF file

        addChild(myLoader);
    }

    private function loadProdComplete(e:Event):void{
        var gameMask : Shape = new Shape;
        gameMask.graphics.beginFill(0xffcc00);
        gameMask.graphics.drawRect(myLoader.x,myLoader.y,640,480);  
        gameMask.graphics.endFill();
        myLoader.content.mask = gameMask;
    }           

Solution

  • As you can read in Adobe's documentation on Stage3D, the special Stage3D layers are located "behind" the regular stage used for 2D content.

    Since any mask applied within the 2D stage exists in a different display list, there is no way to use 2D masks on Stage3D content. If at all possible, the only way to get similar results is to use 3D layers and alpha masks within the Stage3D context.