11 Replies Latest reply on Oct 12, 2009 7:54 PM by _gilado

    Why is swf compiling .mxml so much bigger than compiling .as file

    _gilado Level 1

      I have a test program Test.as which includes a proprietary voice codec and uses urldownload, urlstream,.

       

      When I compile it directly like this: mxmlc Test.as , the resulting .swf file is about ~30Kb

       

      However, if I use the below Test.mxml file and complie it like this: mxmlc Test.mxml , the resulting swf file is ~173Kb.

       

      <?xml version="1.0"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      <mx:Script>
      import Test
      </mx:Script>
      </mx:Application>

       

      What's the extra stuff ?

        • 1. Re: Why is swf compiling .mxml so much bigger than compiling .as file
          leybniz Level 4

          mx:Application  > LayoutContainer  > Container  > UIComponent  > FlexSprite  > Sprite  > DisplayObjectContainer  > InteractiveObject  > DisplayObject  > EventDispatcher

           

          All those classes makes you feel so surprised ))

          • 2. Re: Why is swf compiling .mxml so much bigger than compiling .as file
            Muzak Level 3

            You get (part of) the flex framework along with mxml.

             

            Try adding -keep to the compiler arguments and see what is actually being used (you should end up with a folder containing all the generated .as files).

            • 3. Re: Why is swf compiling .mxml so much bigger than compiling .as file
              _gilado Level 1

              But the swf generated when I compile my Test.as (30Kb) works just as well as the one generated when I compile the Test.mxml (which only import the Test.as and is 170Kb)

              • 4. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                leybniz Level 4

                " ... works just as well as the one generated ... " It's a subjective point, objectively your test.as app lacks lots of functionality, if they looks the same it doesn't really means that they have same potential

                • 5. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                  _gilado Level 1

                  I stripped down my test program to obly display a status line, so it looks like this:

                   

                  package
                  {
                      import flash.display.Sprite;
                      import flash.text.TextField;
                      import flash.utils.Timer;
                      import flash.events.TimerEvent;

                   

                      public class Test extends Sprite
                      {

                          private var statusLine:TextField;
                          private var statusTimer:Timer;
                          private var timerStep:Number = 100;
                          private var elapsedTime:Number = 0;

                   

                          public function Test()
                          {
                              statusLine = new TextField();
                              statusLine.width = 400;
                              statusLine.height = 400;
                              statusLine.multiline = true;
                              statusLine.wordWrap = true;
                              statusLine.text = "Starting";
                              addChild(statusLine);
                              statusTimer = new Timer(timerStep,0);
                              statusTimer.addEventListener(TimerEvent.TIMER,showStatus);
                              statusTimer.start();
                          }

                   

                          private function showStatus(event:TimerEvent):void
                          {
                              var txt:String = "";
                              txt += " > " + Math.round(elapsedTime/100)/10 + " < ";
                              elapsedTime += timerStep;
                              statusLine.text = txt;
                          }
                      }
                  }

                   

                  $  ~/flex/bin/mxmlc Test.as
                  Loading configuration file /home/user/flex/frameworks/flex-config.xml
                  /home/user/test/Test.swf (902 bytes)

                   

                  $ ~/flex/bin/mxmlc -keep Test.mxml
                  Loading configuration file /home/user/flex/frameworks/flex-config.xml
                  /home/user/test/Test.swf (173150 bytes)

                   

                  I looked in the generated/ directory and it has many .as files. Not only are these not needed the swf generated using the mxml file does not work, while the .swf file generated by compiling the Test.as directly does work.

                  • 6. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                    _gilado Level 1

                    >>> It's a subjective point,

                    That's an odd statement. My statemnt is  very objective . The .swf does exactly what I want no more no less!

                     

                    >>> objectively your test.as app lacks lots of functionality

                    ... that I don't need !

                     

                    I am creating an .swf to peform a specific task no to clog the internet by downloading 170Kb of stuff I don't need!

                     


                    Oh, wait... you must be joking, right?

                    • 7. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                      leybniz Level 4

                      That's your choice, you are the Boss!

                      So the original question may be treated as answered I guess,

                      or the aim was not to get the answer but show off how smart you are?

                      Yeah it's all about jokes

                      • 8. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                        _gilado Level 1

                        So looks like you were not joking. Sorry did not mean to offend you.

                         

                        No, question is not answered, and I do need an answer.

                         

                        Is there a way to specify in the mxml file that one only wants the specified packages without uneeded functionality?

                        • 9. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                          leybniz Level 4

                          I see, unfortunately there are no easy way on how to tell mxmlc which packages are good and which are not, since the classes hierarchy tighten with inheritance dependencies.

                           

                          I see you are thinking in terms of *nix packages, and your intention is clear and natural, since you are used to that practice to install needed packages only, but you have to pay for that via high cross-packages dependencies volume. Same story inhere.

                           

                          In Flex it's own way of separating things, we have .swc libraries, Runtime Shared Libraries and Modules for that aim to optimize what's needed now and what could be useful later, then we'll load required module and everybody happy

                           

                          So the clear answer is - if you wannastrip off all the stuff you don't need use modules approach! compile modules against your main application to avoid binary classes duplicates inside module .swf files.  Sounds good?

                          • 10. Re: Why is swf compiling .mxml so much bigger than compiling .as file
                            Muzak Level 3

                            >>> objectively your test.as app lacks lots of functionality

                            ... that I don't need !

                             

                            I am creating an .swf to peform a specific task no to clog the internet by downloading 170Kb of stuff I don't need!

                            Then don't use MLXM and use pure ActionScript. That's why you have a choice, one comes with alot of functionality (adding extra weight), the other doesn't. If you don't need the added functionality, then go with AS only. I really don't see what the problem is.

                             

                            Is there a way to specify in the mxml file that one only wants the specified packages without uneeded functionality?

                            Nope, and there's no need for that, again, that's the difference between an AS and an MXML project. Use whichever suits your needs (which in this case would be AS). The way I see/understand it, you want an MXML project, throw out the added functionality, in which case you'd end up with what you have in the AS project.. seems pointless really.

                            • 11. Re: How to include FABridge in an AS project
                              _gilado Level 1

                              I think my original posting lacked some context.  I was trying to use the FABridge to call from javascript to AS and vice versa.  The only examples I could find showed how to include the FABridge in an mxml file.


                              My solution is inspired by all the postings here:  I compiled the project using the mxml file with the -keep option, then looked in the Test-generated.as (which is my original Test.as wrapped in extra mxml stuff) to see what the compiler did.

                               

                              It turned out I only needed to import bridge.FABridge, add  to my class a variable, a function, and call the function from the constructor.

                               

                              That is, adding the following line to the mxml file:


                              <fab:FABridge xmlns:fab="bridge.*" />

                              is equivalent to adding this code to your class


                              import bridge.FABridge;

                              ...

                              public var _Test_FABridge1 : bridge.FABridge;

                              ...

                              private function _Test_FABridge1_i() : bridge.FABridge
                              {
                              var temp : bridge.FABridge = new bridge.FABridge();
                              _Test_FABridge1 = temp;
                              temp.initialized(this, "_Test_FABridge1")
                              return temp;
                              }

                              ...

                              public function Test()
                              {
                              ....
                              _Test_FABridge1_i();
                              ...
                              }