3 Replies Latest reply on Sep 11, 2006 11:03 AM by ntsiii

    Help Linking AS3 with flex MXML

    I tried Level 1
      Hi,

      I'm an old flash developer used to using the AS2 class based system linking those to my movieclips via the linkage property. I'm trying to pick up flex, but am having trouble wrapping my mind around the way to link the visual assets and the flex mxml with actionscript files. I've also searched the forums and the documentation, but can't seem to come up with all the specific ways of doing this. I do understand that it all compiles to actionscript in the end. Anyway, I'd like to keep all the actionscript in separate files, the way I do with flash. I know all this probably seems basic, but can someone point me to some resources that would give me the initial help I need. Also, any programming insights in this regard would also help.

      Thanks
      Robert
        • 1. Re: Help Linking AS3 with flex MXML
          ntsiii Level 3
          I don't know Flash at all, so your question seems very vague, but generally speaking in Flex:

          * Use <mx:Script source="MyASFile.as"> This is exactly the same as putting the as code inside a script block in the mxml file. It is a true "include"

          * Put the AS code in a Class, using either static or instance methods. If you use instance methods, you need to instantiate the AS class in the mxml file:
          <MyHelperClass id="mhc" .../>
          Then access the functionality via the id:
          mhc.myPublicProperty = "whatever"

          If you use static properties and methods, you can simply:
          import MyHelperClass;
          And use the functionality directly:
          MyHelperClass.myPublicProperty = "whatever";

          The Flex paradign revolves around "components". These can either be mxml, or AS, or swf.

          Post back if you have any specific questions.

          Tracy
          • 2. Re: Help Linking AS3 with flex MXML
            I tried Level 1
            Thanks Tracy, that will definitely get me started. To make my question as clear as I can, the flash paradigm revolves around movieclips. One movieclip can contain many other movieclips, which can contain movieclips and so on, the same way flex components can contain other flex components. In flash, I usually arrange my .fla with one main movieclip controlling all others. This movieclip was linked to a class, through which I manipulated everything else using a top-down oop approach. Other movieclips would be controlled by a class or not as needed. I wanted to set up that same sort of hierarchy for flex applications, with my application tag or main component controlled by a class and other components being controlled by a class as needed. Any ideas on how to set this up?

            Thanks
            Robert
            • 3. Re: Help Linking AS3 with flex MXML
              ntsiii Level 3
              I am pretty sure "MovieClip" is somewhere in the Flex component class hierarchy, and certainly, the architecture you describe is valid for a Flex application.

              The mx:Application tag is the top-level (_root in Flash) and the rest of the app is built of nested components.

              Tracy