3 Replies Latest reply on Dec 2, 2007 8:04 AM by peterent

    Run code from RSL

    Zolotoj Level 3
      I have managed creation of my first RSL (or so I think). My RSL consists of a package that has just one class that looks like this:
      package RSL_Package
      {
      public class Test
      {
      import mx.controls.Alert;
      public function initMod():void
      {
      Alert.show("1");
      }
      }
      }

      In my module I am trying to run this test code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" paddingTop="5" horizontalCenter="true"
      initialize="initMod()">
      but compiler says: "1180: Call to a possibly undefined method initMod."
      What do I need to do to make this work?

      Thanks
        • 1. Re: Run code from RSL
          peterent Level 2
          There really isn't a need to use RSLs with Modules. You have to download something - either classes in an RSL which are then later used/referenced by loaded SWFs (apps or Modules) - or - a main app with those same classes tucked into it which are then later used/referenced by loaded SWFs (apps or Modules). For use with Modules, you *still* have to have a main app, so why not just compile the main app with the classes you'd have put into the RSL? Saves you a step and have the same effect.

          Your initMod() function is contained in the class Test. So you have to instantiate an instance of Test and then you can invoke the function. For example, suppose the RSL/mainApp contained the class String. How would you execute the String class's replace() function? You would have to instantiate an instance of String and then invoke the method on that instance.

          (String, btw, is a Flash Player class is therefore already in the Flash Player itself).

          So your Module has to do a var t:Test = new Test() and then t.initMod().
          • 2. Re: Run code from RSL
            Zolotoj Level 3
            I can't get it working.
            Here is code from my modlue:
            <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" paddingTop="5" horizontalCenter="true"
            xmlns:customComponents="CustomComponents.*" initialize="initModule()">
            <mx:Script>
            <![CDATA[
            private function initModule():void
            {
            var t:Test = new Test();
            t.initMod();
            }
            ]]>
            </mx:Script>
            Class Test is in CustomComponents:
            package CustomComponents
            {
            public class Test
            {
            import mx.controls.Alert;
            public function initMod():void
            {
            Alert.show("1");
            }
            }
            }
            This code:
            var t:Test = new Test();
            give this compile error:
            1046: Type was not found or was not a compile-time constant: Test.
            • 3. Re: Run code from RSL
              peterent Level 2
              Where's the import statement for your Test class? Every class you use needs to be declared so the compiler knows where to find it. The exception is that from within MXML files, flash classes are automatically declared.