4 Replies Latest reply on Jan 30, 2012 2:24 AM by dl_page

    Trying to get my head around Flex :=)


      Hi everyone,


      I am a flex noob, though I have 10 years dev experience in VB and PHP, and a bit less in JS, C and PICBasic. I get algorithms and general programming concepts without too much problems, but I am having a mental block with Flex. I'm playing with a mobile project, as this can have several repercussions on what is available in the Flex language, and what is not....


      I have been playing with a Hello World app giving me a lot of cryptic errors and I have managed to work around most of them, and I can get the app to do most of what I want today, though I have some minor headaches if someone can take a few minutes to clarify the 5 points below for me, I'd be grateful.


      1) Global static classes

      I have got static classes working, though not really "global". Is there any way to declare a static class once without having to "import path.to.package;" in every individual mxml file, or do I, à la C, have to always import this, like I would have to redeclare my header includes in each source file?


      2) Calling a static class, and calling a method from a click event

      Once again, static classes, as I don't need to instanciate them... I for example want to call a method of a static class from a button's click event. This does not seem to work, as the package that contains it is not imported by the button that is clicked. Am I doing somthing wrong, or does the button have to call a local function in the same mxml file that calls from the code block the object?


      Quick and dirty pseudo-code as I am not sure that I am clear enough. Can this be done ? (but how are the imports done in this case? ) :


      <button click="staticClass.staticMethod()">


      or is this the only way? :


      <button click="localFunction()">


        function localFunction() {

          import path.to.my.static.class.package;   





      3) No global static variables?

      There are a lot of info about global static variables (I want to store some common paths and urls in a couple of them rather than generating a static settings package and class, importing it into each view and generating local functions to access the static methods!). Some pages say to use Application.application.myGlobalVarName to do this, yet my Application object does not have an application child... Am I doing somthing wrong?



      4) (Default package)
      I create an ActionScript file in the (default package) directory under the parent "src". Flash Builder's autocomplete sees the class, sees the methods, but I get a systematic error when I try to use them...
      from the runtime engine if I try to use them ? Do I have to put it in a named subfolder (and reference with an import)?


      5) Dynamic control text for buttons and other controls
      I can define in the script a variable, lets say public var v:String = "test", then define a <button id="b" label="{this.v}"> and the button will display "test" : The button is pulling the data from the script. Is the opposite not possible, like b.label = v ? I can't see why not, and the IDE's autocomplete seems to agree with me as it proposes the button and property.... yet the error window complains "1120 Access of undefined property b".... The autocomplete once again says yes and the compiler once again says no. If the IDE does not know what is correct, how do I?!? :::confused:::


      Well, that's about it for now. If anyone can give my any explanations regarding these points, they will really help me getting a jumpstart into this language!!





      Message was edited by: dl_page - forgot to add an import to the pseudocode...

        • 1. Re: Trying to get my head around Flex :=)
          Flex harUI Adobe Employee

          I suggest reading up on object-oriented coding.  Some of the books and training videos on ActionScript might have a good introduction.


          Just about everything is an object, in Basic most everything is a variable.  You have to make it clear in your code what object you want to use and that usually requires import statements.  An MXML file is just shorthand for an AS class definition.  The code in your event handlers just become bodies of function in that definition.  Use –keep-generated-actionscript to see how it gets mapped.  You can just stick import statements in your script block to apply them to event handlers.


          A class definition has class/static scope and instance scope and where you stick your code defines which scope it is in and can cause errors.



          1 person found this helpful
          • 2. Re: Trying to get my head around Flex :=)
            dl_page Level 1

            Hi Flex harUI,


            Thanks for taking the time to answer. OOP is not a problem, as JS and VB.net both have the "everything is an object" notion, but I have limited knowledge at this time of Actionscript, and finding out what object has what scope from what file/directory can be confusing especially as the Flex IDE and the compiler itself seem to get confused as to what is valid (the IDE autocomplete should not show objects that are not in the current scope - but it does )... I think my major failing in understanding this was fully taking this into account.


            The other points I can work at to get to, though I still cannot understand why I cannot seem to call or import anything that is placed in the (default package) folder...


            Anyway, from there, I'm going to keep plugging away at some examples, thnking object, and see where I can go from there...




            • 3. Re: Trying to get my head around Flex :=)
              Flex harUI Adobe Employee

              Regarding stuff in the default package:  In MXML, the default package needs to be given a prefix like this:


              <s:Application xmlns:local=”*” ...>


              Then a class in the default namespace is declared as:


              <local:MyComponent />


              • 4. Re: Trying to get my head around Flex :=)
                dl_page Level 1

                Thanks for the heads up, and sorry for the wait. I'll give it a whirl this week in a couple of my proof of concept tests.


                Most languages I have managed to learn by playing with, at least to start, but it looks like I need a copy of flex and actionscript for idiots to get kickstarted.


                Once again, thank you for your input!