JabbyPanda’s travel to RIA world / 35 posts / categories / 85 comments / feed / comments feed

How to hide the unwanted content visible outside of mx:SWFLoader boundaries

The issue:

I was stumbled upon once ago when I loaded my external SWF file authored by the Flash IDE by the help of component and suddenly (?) every content object that was originally placed outside of the Stage inside the Flash IDE became visible in my Flex 2 based web application outside of the boundaries after loading sequence for my external SWF file was over (the file is Flash8 based, AVM1 if this matters).

The corresponding task in Adobe JIRA bug-database:
http://bugs.adobe.com/jira/browse/SDK-14590

I currently fight this issue by applying the mask over the content that is loaded by the component, see the code below, may be you can find it helpful too:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
    resize="applyMask()" >

    <mx:Script>
        <![CDATA[
            private function applyMask() : void {
                if (swf != null &&
                    swf.content != null &&
                    swf.content.loaderInfo.width > 0 &&
                    swf.content.loaderInfo.height > 0) {
                    var scaleRatioX : Number = swf.content.loaderInfo.width /
                                                    this.width;
                    var scaleRatioY : Number = swf.content.loaderInfo.height /
                                                   (this.height - this.controlBar.height);
                    var scaleRatio : Number = Math.max(scaleRatioX, scaleRatioY);

                    swf.width = swf.content.loaderInfo.width > 0 ?
                          Math.round(swf.content.loaderInfo.width / scaleRatio)  : 100;
                    swf.height = swf.content.loaderInfo.height > 0 ?
                          Math.round(swf.content.loaderInfo.height / scaleRatio) : 100;

                    var s : Shape = new Shape();
                        s.graphics.beginFill(0xFFFFFF);
                     s.graphics.drawRect(0, 0,  swf.width, swf.height);
                     s.graphics.endFill();
                     swf.addChild(s);
                     s.visible = false;
                     swf.mask = s;
                }
            }
    ]]>
    </mx:Script>
    <mx:SWFLoader id="swf"
        complete="applyMask()"
        source="navigation.swf"/>
</mx:VBox>

2 Comments

  1. Keith H — February 14, 2008 #

    This is something I may have to consider at work.
    At work, a lot of our Flash(8) designers hid content off the stage area.
    If older Flash 8 content will be displayed in our new Flex projects, this is something to remember among things.

  2. Arthur Nemirovsky — February 29, 2008 #

    I had this problem for some months last year on a video site I was working on, that has flash ads or video ads that play prior to the videos, some of the advertisers had sent their creative, and I was experiencing this problem, researching for months, did not find anything, the solution I used, was masking the files in flash, ie the swf content that is being loaded, this could be a daunting task over time, and required that the advertisers send their creatives in fla’s. I found this post searching for something else in google, I wish this was available sooner, and I am glad I am not the only person with this problem. Thank you very much for this solution. This should be at the top of google search. very helpful.

Leave a comment

Powered by WP Hashcash