0 Replies Latest reply on Sep 22, 2008 6:57 AM by PallavN

    Problem in masking when loading a Flash 8 movie

    PallavN
      Hi everyone,

      We've a Flex project that needs to load a Flash 8 movie (AS2). The movie has a masking which doesn't seem to render well in Flex (when loaded for second time). Appended below is the code and attached is the project.

      Flex Code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" initialize="initApp()">
      <mx:Script>
      <![CDATA[
      import flash.net.URLRequest;
      import mx.core.UIComponent;

      private function initApp():void
      {
      var loader:Loader=new Loader();
      var urlReq:URLRequest=new URLRequest("for_musk.swf");
      loader.load(urlReq);

      var loader2:Loader=new Loader();
      var urlReq2:URLRequest=new URLRequest("for_musk.swf");

      loader2.load(urlReq2);

      var ui:UIComponent=new UIComponent;
      addChild(ui);
      var ui2:UIComponent=new UIComponent;
      addChild(ui2);
      ui2.y=200;
      ui.addChild(loader);
      ui2.addChild(loader2);
      }
      ]]>
      </mx:Script>
      </mx:Application>

      The SWF file (being loaded) has the following code to illustrate a general masking:
      var _mc1:MovieClip = this.createEmptyMovieClip ("mc1", 1);
      with (_mc1)
      {
      beginFill(0xFF00FF);
      moveTo(0, 100);
      curveTo(0,200,100,200);
      curveTo(200,200,200,100);
      curveTo(200,0,100,0);
      curveTo(0,0,0,100);
      endFill();
      }

      var _mc2:MovieClip = this.createEmptyMovieClip ("mc2", 2);
      with (_mc2)
      {
      beginFill(0xFF0000);
      moveTo(10, 10);
      lineTo(100, 10);
      lineTo(100, 100);
      lineTo(10, 100);
      lineTo(10, 10);
      endFill();
      }
      _mc1.setMask(_mc2);
      var b1:Object=_mc1.getBounds(_mc1);
      var b2:Object=_mc1.getBounds(_mc2);
      path1.autoSize=path2.autoSize=true
      path1.text=_mc1;
      path2.text=_mc2;
      bound1.autoSize=bound2.autoSize=true
      bound1.text="_mc1: "+"xMin-"+b1.xMin+", xMax-"+b1.xMax+", yMin-"+b1.yMin+", yMax-"+b1.yMax;
      bound2.text="_mc2: "+"xMin-"+b2.xMin+", xMax-"+b2.xMax+", yMin-"+b2.yMin+", yMax-"+b2.yMax;

      The result is that whichever instance of the SWF gets loaded first produces the correct result (in terms of masking). The second one falters and shows the mask as well as the underlying movie (and doesn't perform the masking function).

      Also, the getBounds method of Flash generates ‘undefined’ values for the instance that was loaded second.

      We have added textbox to track down the moviecilp structure and getBounds values.

      hitTest is also behaving and producing weird results for these type of situations.

      Screenshot and code can be downloaded from http://www.igcomm.com/Flex_Masking_Error.zip

      Any help would be greatly appreciated.
      Thanks,
      Pallav