4 Replies Latest reply on Feb 10, 2008 10:38 PM by atta707

    Pcakage Help

    vij010
      Hi...

      What's the correct way of creating and including a package in Flex ?

      I choose File - > Create an Actionscript Class and have this inside....

      package Addition
      {
      public class Addnumbers
      {
      public function Addnumbers()
      {
      super();
      public var add1:Number
      public var add2:Number
      var total:Number=add1+add2;
      return total;
      }
      }
      }


      But when I go to the MXML side.... this is the code....

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="427" height="318">
      <mx:Script>
      <![CDATA[
      import Addition.Addnumbers;
      import mx.controls.Alert;
      ]]>
      </mx:Script>
      <mx:Panel x="10" y="10" width="407" height="298" layout="absolute" title="Sample Application to Show Classes and Packages">
      <mx:TextInput x="113" y="25" id="add1"/>
      <mx:TextInput x="113" y="55" id="add2"/>
      <mx:Label x="10" y="29" text="Enter Number :" width="95"/>
      <mx:Label x="10" y="56" text="Enter Number :" width="95"/>
      <mx:LinkButton x="191" y="85" label="Show Total " enabled="true" click="showtotal();"/>
      </mx:Panel>

      </mx:Application>

      The complier gives me an error saying that Addition.addnumbers can'r be found. What's wrong ?
        • 1. Re: Pcakage Help
          Arty13
          Not sure if I'm correctly adding my package to my project, but what I do, is... Import a &quot;File System&quot; (aka a folder) to my project and use my package that way.

          So if you do the same as me, under your project you will have a folder called &quot;Addition&quot; and in that folder you would have your class file which would be called &quot;Addnumbers.as&quot;

          If there is a better way to do this, please let me know. (hope this helps you in the meantime)

          Thanks,

          Art
          • 2. Re: Pcakage Help
            Gregory Lafrance Level 6
            Package names must relate to folders, so if you use the package name Addition, here must be a folder &quot;Addition&quot; somewhere within the project &quot;source path&quot;. I tried this and initially got your error, then it mysteriously went away. Try Project - Clean from the menu, and try xmlns=&quot;Addition&quot; as well.
            • 3. Re: Pcakage Help
              vij010 Level 1
              Hi,


              I have this MXML code for a very simple application....

              [CODE]
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="439" height="356">
              <mx:Script>
              <![CDATA[
              public function showresult():void
              {
              import mx.controls.Alert;
              import addition.Addnum;
              [Bindable]
              var result:Number=new Number;
              result=
              Alert.show(result.toString(),'Flex 2.0');

              }
              ]]>
              </mx:Script>
              <mx:Panel x="10" y="10" width="419" height="336" layout="absolute">
              <mx:TextInput x="56" y="31" id="add1"/>
              <mx:TextInput x="56" y="61" id="add2"/>
              <mx:Button x="154" y="91" label="Result" click="showresult()"/>
              </mx:Panel>
              </mx:Application>


              and the package....

              package addition
              {
              public class Addnum
              {
              public function Addnum()
              {
              super();
              var add1:Number
              var add2:Number
              var result:Number= new Number
              result=add1+add2;
              }

              }
              }

              But I am unable to fire the addnum() when to calculate the sum of the 2 values. How do I do this in AS ?..is this the correct way ?
              • 4. Re: Pcakage Help
                atta707 Level 2
                Shouldn't Addnum.Addnum() function take two parameters? As in:

                public function Addnum(add1:Number, add2:Number) : Number
                {
                // super(); // what is this?
                var result:Number= new Number
                result=add1+add2;
                return result;
                }

                The question is how does Addnum.Addnum() get the reference of the you input boxes if not thru parameters?