5 Replies Latest reply on Nov 11, 2009 9:27 PM by Flex harUI

    SWFLoader that unfortunately sets Stage.scaleMode

    chrisisme Level 1

      In a Flex project I have been working on, I've received a new SWF asset to incorporate. No problem usually. However, this asset is setting the stage's scaleMode to showAll. OUCH. This has the effect of this: Flex app loads and looks fine, SWFLoader is later called and the asset is loaded as the SWFLoader's source. The entire stage is scaled up at least 3x the size. On the complete event for the loader I go ahead and set the scaleMode back to noScale, but then the application jumps back to looking correct. The problem is the jumping up then back again.

       

      I am not able to have the asset rebuilt, so I am stuck with what I have. How can I work around this from Flex. Since the stage is shared, this SWF keep dorking everything up.

        • 1. Re: SWFLoader that unfortunately sets Stage.scaleMode
          Flex harUI Adobe Employee

          Depends on what the asset really is.  If you only need a symbol from it, you can try embedding just those symbols and that might skip the code that calls showAll.

           

          If you need the whole SWF because you want the timeline but don't care about what it actually does, you can deploy it on a different domain and then it won't have access to the stage.  It will throw a security error but only folks with debugger players will see it.

           

          Another option is to find out where code that changes scaleMode is.  If it is in a particular class in AS3 in then SWF, you can try creating a custom version of that class in your main app.  You version of the class will supercede the one in the SWF.

           

          Another option is to find out when the code changes scaleMode.  It might be that you can double-check on enterFrame or render events and set it back before the player actually draws it in the wrong scale mode.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          1 person found this helpful
          • 2. Re: SWFLoader that unfortunately sets Stage.scaleMode
            chrisisme Level 1

            Wow, great answer, by far one of the most helpful answers I have received on any development forum. Thank you.

            Follow-up question. I do need the full SWF file. It is actually an Object2VR generated SWF. I've decompiled it, and have the .as files. I did not realize that I can create a main application version of that class and it would supersede it. That is amazingly helpful since I have had similar issues with other assets. My follow-up question relates to where this custom version should go in the project so this works. I am building in a Flex Library Project, so this would actually need to supersede from there. I'm just not sure I understand where this class should go so that the SWF file will use my version instead of its built in one.

             

            EDIT: The classes used in the original SWF are all in the default package {}. An issue I ran into is that the one object I need extends another which imports several others, and so forth and so on. Without creating local versions of all of these, I just don't see how to get this approach to work, though it really would be the most powerful.

            • 3. Re: SWFLoader that unfortunately sets Stage.scaleMode
              msakrejda Level 4

              Ah, the joys of monkey patching. You only need to ensure that it is referenced in both your Flex Library project and the eventual Application (I believe), and Flash Player will take care of the rest. I generally have an array of dummy references somewhere in the main Application class (or somewhere else I know will be referened) when I need to do something like this. E.g.,

               

              var dummyRefs:Array = [ MonkeyPatchedClass, OtherMonkeyPatchedClass ];

               

              (with the appropriate imports, obviously--although you won't need imports if the classes you're monkey-patching are using the top-level package). Note that you need to have the exact same as the original assets (i.e., same package structure and same class name).

               

              You can add the swf as an externally linked library during compilation so you don't pull in the entire dependency chain.

              • 4. Re: SWFLoader that unfortunately sets Stage.scaleMode
                chrisisme Level 1

                Okay, I am sort of following that, but I am starting to feel totally green again.

                 

                I have one class in the SWF that I need to supersede. It is VrObject.as. It is in the default package, and it extends GgViewer. This is where everything goes into dependency hell. If I don't also include the GgViewer class, then all the "override protected function" calls in the VrObject toss up compile problems. But as soon as I add a custom version of the GgViewer class it goes south. Is there a way that I am not seeing to use the custom VrObject.as without the compiler worrying about it not seeing the dependencies since they are all in the SWF which won't be loaded until load time.

                • 5. Re: SWFLoader that unfortunately sets Stage.scaleMode
                  Flex harUI Adobe Employee

                  Unfortunately, you will need the VrObject.as and all of its dependencies like GgViewer and whatever else it needs.  Hopefully you can get your hands on the actual GgViewer.  You will want to use the actual copies of every AS file except VrObject or whatever class is accessing the stage.

                   

                  Note also that if you've decompiled the SWF and know when it sets scaleMode, it might be possible to find out which frame that is going to happen in and when it will happen in that frame and reset scaleMode right after instead of trying to do this trick.

                   

                  Finally, our pattern for class inclusion is:

                   

                  import foo.bar.SomeClass; SomeClass;

                   

                   

                   

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui