1 2 Previous Next 77 Replies Latest reply on Mar 24, 2010 3:01 PM by benethridge

    Concept of Subroutine or Method in MXML?

    benethridge

      Hi. Does Flex MXML have the concept of a subroutine (like VB) or a method (like ActionScript)?

       

      Reason I ask is that I have some MXML code which will be duplicated (yecch!) unless I can refactor it into a subroutine of some sort.

       

      Ben Ethridge

      Senior Java Developer / Flex Newbie

        • 1. Re: Concept of Subroutine or Method in MXML?
          msakrejda Level 4

          I'm not quite sure what you are asking. You can put <mx:Script> blocks in your MXML to define methods in ActionScript. You can define self-contained Components and reuse them within your application or across applications. You can also use MXML States to handle some reusability aspects really neatly. It depends on what you're trying to achieve.

          • 2. Re: Concept of Subroutine or Method in MXML?
            benethridge Level 1

            Most computer languages, even in the early days, had the concept of a "subroutine".  In Visual Basic they are called "Sub". In COBOL they were called PERFORM statements, if I remember correctly. In java they are called methods.

             

            It falls under the general rule of "DRY" programming, i.e. Do Not Repeat Yourself:

             

            http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

             

            That's the new term for a very ancient rule of good program design.

             

            Obviously I could recode any MXML in ActionScript, which appears to be DRY, but if I want to stay at the MXML level, I have not yet found a way to (ahem) "stay DRY" :-)

             

            Could possibly be done by making everything a component, but that seems to be a bit of a kludge, i.e. using components for something other than their original intent.

             

            Ben

            • 3. Re: Concept of Subroutine or Method in MXML?
              benethridge Level 1

              Sometimes it feels like we're going backwards, i.e. the newer languages are more primitive than the older ones. For example, JSP is the only language in J2EE that has the concept of an include file (go figure)...and this (relatively) new MXML does not even have sub'ing.  Pretty sad.

               

              I just tried using the <mx:Module> to solve the above problem, but alas, even though I selected the "Optimize for application", it was not able to understand that the variables in the <mx:Module> were declared in the <mx:Application>. Is there a way to tell it? i.e. have it behave like a parameterized method?  If there isn't, there should be.

               

              Otherwise, if I want to eliminate code duplication, I think my only option is to recode the entire app in ActionScript (as opposed to MXML).  :-(

               

              Sorry for the rant, but IMHO, like relational database theory, all languages should be DRY coz code duplication is probably the #1 nemesis of coders.  I'm hoping Adobe is listening and will enhance for DRY next version.

               

              Ben

              • 4. Re: Concept of Subroutine or Method in MXML?
                Flex harUI Adobe Employee

                A mx:Module follows the modular concepts of computer science.  Variables are

                scoped within.  If you want to access the application you have to reference

                the Application.

                 

                I am not a language expert, but I disagree that newer languages are going

                backwards.  A language and its execution environment can serve specific

                goals than more general languages and thus do not need to have every feature

                of general languages.  If, for example, you are creating language for really

                small embedded applications, you do not necessarily need to provide features

                to load code.

                 

                MXML is one of a new class of "declarative" languages.  I don't think

                delcarative languages are under any obligation to implement methods as I

                don't see methods as part of declarative programming.  MXML is essentially

                shorthand for specifying an ActionScript class.  In fact, you can use the

                -keep option to see the generated ActionScript class.  MXML provides the

                mx:Script block to allow you to specify ActionScript that cannot be easily

                represented in a declarative fashion.

                 

                To me, it isn't really any different than the ability we once had to use a

                #asm declarative to inject 8086 assembly code in the body of a 'C' method in

                Microsoft C compilers several years back.  C provides a friendlier layer on

                top of assembly/machine code, but you can't get as direct control over the

                output.  MXML provides a friendlier layer for specifying AS.

                • 5. Re: Concept of Subroutine or Method in MXML?
                  msakrejda Level 4

                  Many people build massive, modular applications in Flex while adhering to DRY, so I don't think the problem is lack of support from Flex. I think we're not answering your question clearly because we're not sure what (beyond the vague term "reuse") you are trying to achieve. Would looking at an example (like, say, restaurant finder: http://www.adobe.com/devnet/flex/samples/restaurant/ ) make things clearer for you?

                  • 6. Re: Concept of Subroutine or Method in MXML?
                    benethridge Level 1

                    If MXML is truly declarative, then all it should do is declare (like say HTML). Features such as <mx:Transition>, <mx:Sequence> and <mx:Parallel> do not appear to be declarative to me. They appear to be more procedural.  I would not be surprised to see loops and if conditions next, similar to JSTL in JSP, which probably started out declarative as well.

                     

                    My problem with MXML is more practical in nature (as opposed to semantic, i.e. declarative vs non-declarative).  If programmers get in a deadline bind and don't have an easy way to avoid code duplication (by using JSP and C includes, cobol copybooks, vb subroutines, java methods, etc.)  they're going to duplicate, and duplication IHMO is the greater of the two evils (i.e. I realize the potential evil of copybooks and includes).

                     

                    Groovy is a brand new language which has DRY as a fundamental (but ancient) concept. Makes perfect sense to me. If you are disagreeing with DRY as a necessary feature of a language, then I suppose we'll just have to agree to disagree.

                     

                    Ben

                    • 7. Re: Concept of Subroutine or Method in MXML?
                      benethridge Level 1

                      Hi. I don't think it's lack of support from Flex. I think it's a lack of certain DRY features in MXML.  Here is what I mean by "reuse":

                       

                       

                          <mx:transitions>
                                  <mx:Transition fromState="" toState="Initial">
                                      <mx:Sequence>
                                          <mx:SetPropertyAction name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                          <!-- Move it across the screen into reading position. -->
                                          <mx:Move duration="{moveDuration}" targets="{[initialText,initialText1,initialImage]}"/>
                                      </mx:Sequence>
                                  </mx:Transition>
                                  <mx:Transition fromState="Designing" toState="Initial">
                                      <mx:Sequence>
                                          <!-- fadeout what is shown -->
                                          <mx:Fade duration="{fadeDuration}" targets="{[designingImage,designingText,designingText1,designingText2]}" alphaFrom="1.0" alphaTo="0.0"/>
                                          <mx:SetPropertyAction name="visible" targets="{[designingImage,designingText,designingText1,designingText2]}"/>

                       

                                          <!-- Fadein what should now be shown. -->
                                          <mx:Fade duration="1" targets="{[initialImage,initialText,initialText1]}" alphaFrom="0.0" alphaTo="1.0"/>
                                          <mx:SetPropertyAction name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                          <!-- Move it across the screen into reading position. -->
                                          <mx:Move duration="{moveDuration}" targets="{[initialText,initialText1,initialImage]}"/>
                                      </mx:Sequence>
                                  </mx:Transition>
                                  <mx:Transition fromState="More" toState="Initial">
                                      <mx:Sequence>
                                          <!-- fadeout what is shown -->
                                          <mx:Fade duration="{fadeDuration}" targets="{[moreImage,moreText]}" alphaFrom="1.0" alphaTo="0.0"/>
                                          <mx:SetPropertyAction name="visible" targets="{[moreImage,moreText]}"/>

                       

                                          <!-- Fadein what should now be shown. -->
                                          <mx:Fade duration="1" targets="{[initialImage,initialText,initialText1]}" alphaFrom="0.0" alphaTo="1.0"/>
                                          <mx:SetPropertyAction name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                          <!-- Move it across the screen into reading position. -->
                                          <mx:Move duration="{moveDuration}" targets="{[initialText,initialText1,initialImage]}"/>
                                      </mx:Sequence>
                                  </mx:Transition>

                      ...

                       

                      Note the 3 lines of duplicated code in the "Fadein" section.

                       

                       

                      Those 3 lines should be refactored/modularized to eliminate the duplication, but I don't yet see how to do that.

                       

                      Ben

                      • 8. Re: Concept of Subroutine or Method in MXML?
                        JeffryHouser Level 4

                        The equavilent of a subroutine is a function with a return type of void.

                         

                        Subroutines, by definition are part of procedural / imperative programming.  Most programming languages these days are hybrids taking elements from Objecto Oriented and procedural languages.

                         

                        ActionScript leans towards object orientation, and therefore does not have explicit subroutines.

                         

                        MXML, for most purposes, is a markup language, not a programming language.  We can use tricks to include ActionScript code in an MXML document, though.

                         

                        I have no issues programming in Flex while also following DRY Principles.

                        • 9. Re: Concept of Subroutine or Method in MXML?
                          JeffryHouser Level 4

                          You can't do it in the same file as far as I know.  But you can create a new class, something like this:

                           

                           

                           

                                          <mx:Sequence>

                           

                                              <!-- Fadein  what should now be shown. -->

                           

                                              <mx:Fade  duration="1" targets="{[initialImage,initialText,initialText1]}"  alphaFrom="0.0" alphaTo="1.0"/>

                           

                                               <mx:SetPropertyAction name="visible"  targets="{[initialText,initialText1,initialImage]}"/>

                           

                           

                                           </mx:Sequence>

                           

                           

                           

                          And then you would use that new class:

                           

                              <mx:transitions>
                                      <mx:Transition  fromState="" toState="Initial">
                                           <mx:Sequence>
                                              <mx:SetPropertyAction  name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                               <!-- Move it across the screen into reading position. -->
                                               <mx:Move duration="{moveDuration}"  targets="{[initialText,initialText1,initialImage]}"/>
                                           </mx:Sequence>
                                      </mx:Transition>
                                       <mx:Transition fromState="Designing" toState="Initial">
                                           <mx:Sequence>
                                              <!-- fadeout what is  shown -->
                                              <mx:Fade  duration="{fadeDuration}"  targets="{[designingImage,designingText,designingText1,designingText2]}"  alphaFrom="1.0" alphaTo="0.0"/>
                                               <mx:SetPropertyAction name="visible"  targets="{[designingImage,designingText,designingText1,designingText2]}"/>

                           

                                               <!-- Fadein what should now be shown. -->

                                              <ns1:MyCustomEffect />

                           

                                               <!-- Move it across the screen into reading position. -->
                                               <mx:Move duration="{moveDuration}"  targets="{[initialText,initialText1,initialImage]}"/>
                                           </mx:Sequence>
                                      </mx:Transition>
                                       <mx:Transition fromState="More" toState="Initial">
                                           <mx:Sequence>
                                              <!-- fadeout what is  shown -->
                                              <mx:Fade  duration="{fadeDuration}" targets="{[moreImage,moreText]}"  alphaFrom="1.0" alphaTo="0.0"/>
                                               <mx:SetPropertyAction name="visible"  targets="{[moreImage,moreText]}"/>

                           

                                              <!-- Fadein  what should now be shown. -->

                                              <ns1:MyCustomEffect />

                                               <!-- Move it across the screen into reading position. -->
                                               <mx:Move duration="{moveDuration}"  targets="{[initialText,initialText1,initialImage]}"/>
                                           </mx:Sequence>
                                      </mx:Transition>

                          ...

                           

                          That's the gist.

                          1 person found this helpful
                          • 10. Re: Concept of Subroutine or Method in MXML?
                            Flex harUI Adobe Employee

                            mx:Sequence is an Array, so you're asking the equivalent of:

                             

                            If I have 3 arrays...

                             

                            Var arr1:Array = ["Lions", "Tigers", "Bears", "Giraffes", "Elephants"];

                            Var arr2:Array = ["Pumas", "Leopards", "Bears", "Giraffes", "Elephants"];

                            Var arr3:Array = ["Dogs", "Bears", "Giraffes", "Elephants"];

                             

                            ..how can I only type Bears, Giraffes, Elephants once.

                            • 11. Re: Concept of Subroutine or Method in MXML?
                              benethridge Level 1

                              The equavilent of a subroutine is a function with a return type of void.

                              I know.  That's just semantics, and if that's true, then you DO have the CONCEPT of a subroutine in ActionScript, right?

                               

                              ...but I'm not arguing the DRY features of ActionScript. I have no beef with ActionScript....well not today :-)

                               

                              My beef is with MXML, and I wouldn't be beating up on MXML if the three popular Flex books I bought are all touting the benefits of it and are using it heavily...which was great until (a) I started using it on an industrial-strength app and ran into the code problem shown above and (b) I read a statement in an article (sorry, I can't remember where it is now) that essentially said that one could only use MXML for "simple" apps.

                               

                               

                              I mean, if Adobe removed functions from ActionScript, I imagine you'd be singing a different tune.   That's my beef with MXML.  If you stay in it for the most part, you have no concept of a parameterized function. 

                               

                              I'm thinking the best way to use it is as an initial "storyboard" from which I would generate the ActionScript code, throw away the MXML and use the ActionScript as my only source code.  Is that what most people are doing, i.e. whenever they have a DRY problem, refactor it into ActionScript?

                               

                              Ben

                              • 12. Re: Concept of Subroutine or Method in MXML?
                                msakrejda Level 4

                                It's not *that* crazy a request:

                                 

                                var bge:Array = ["Bears", "Giraffes", "Elephants"];

                                var arr1:Array = ["Lions", "Tigers"].concat(bge);

                                var arr2:Array = ["Pumas", "Leopards"].concat(bge);

                                var arr3:Array = ["Dogs"].concat(bge);


                                ; )

                                 

                                That said, Jeffry's approach should work well with inline components in Flex 4 to solve this, no?

                                 


                                1 person found this helpful
                                • 13. Re: Concept of Subroutine or Method in MXML?
                                  benethridge Level 1

                                  Oh, sorry. Didn't see this one before  posted. You class concept may be a solution. I'll try it out later. Gotta run. Thanks.

                                   

                                  "I'll be back" :-)


                                  Ben

                                  • 14. Re: Concept of Subroutine or Method in MXML?
                                    benethridge Level 1

                                    var bge:Array = ["Bears", "Giraffes", "Elephants"];

                                    var arr1:Array = ["Lions", "Tigers"].concat(bge);

                                    var arr2:Array = ["Pumas", "Leopards"].concat(bge);

                                    var arr3:Array = ["Dogs"].concat(bge);

                                     


                                     

                                    This looks like ActionScript, not MXML.  Again, my beef is not with ActionScript. In fact, from your code, I'd say that's about as DRY as you can get ;-)

                                     

                                    Back to Jeffrey's solution, which appears to have some potential.  Is this a feature of Flex 4? I'm at 3.5 and all my brand new books are for 3.x.

                                     

                                    Can someone point me to the syntax for what he's getting at?  I don't see in in any of my books yet.

                                     

                                    Ben

                                    • 15. Re: Concept of Subroutine or Method in MXML?
                                      msakrejda Level 4

                                      Alex pointed out that what you want to do is difficult even in ActionScript. I was pointing out that it can still be done.

                                       

                                      Re: Jeffry's answer: that should work in Flex 3. In Flex 4, you would not have to define a separate MXML Component (you can define it inline), but it should still work in 3. What part of the syntax is giving you trouble? It's just defining a component (you'll need to expose properties for the targets, though).

                                      • 16. Re: Concept of Subroutine or Method in MXML?
                                        benethridge Level 1

                                        What part of the syntax is giving you trouble? It's just defining a component (you'll need to expose properties for the targets, though).

                                         

                                        All of it at this point. Bear with me. I'm new to Flex.  I'm sure it's easy to define a custom component with "exposed properties for the targets", once you've done it a time or two. I mean, for starters what kind of component would I inherit from? canvas? module?

                                         

                                        I mean, we'd want the smallest, simplest "component" we could inherit from, right? ...coz essentially all we're trying to do is emulate an include file like in JSP or C, merely to avoid simple code duplication, if I'm understanding the essence of Jeffrey's <ns1:MyCustomEffect /> refactoring.

                                         

                                        I'm ok with it not being in-line for now, i.e. until Flex 4.x.

                                         

                                        Ben

                                        • 17. Re: Concept of Subroutine or Method in MXML?
                                          JeffryHouser Level 4

                                          It is how you create components.  Any book from Flex 2 onward should cover it.

                                           

                                          Put the encapsulated code in a one file.

                                          Import it in the second file; then just call the component.

                                          • 18. Re: Concept of Subroutine or Method in MXML?
                                            benethridge Level 1

                                            Oh, sorry. I thought you meant writing something in ActionScript.  I think I found what you meant here, including "exposing the properties for the target":

                                             

                                            http://www.adobe.com/devnet/flex/quickstart/building_components_in_mxml/#ref_props

                                             

                                            Ben

                                            • 19. Re: Concept of Subroutine or Method in MXML?
                                              benethridge Level 1

                                              Put the encapsulated code in a one file.

                                              Import it in the second file; then just call the component.

                                               

                                              If there were not variables to pass back and forth, I think it would be as simple as you say, but I'm thinking it is not quite that simple coz I have variables I need to pass down into the new custom component, similar to the way you'd pass object references to a java method.

                                               

                                              I'm thinking now that this is what msakrejda meant by "expose properties for the targets", i.e.:

                                               

                                              <mx:Fade duration="1"  targets="{[initialImage,initialText,initialText1]}" alphaFrom="0.0"  alphaTo="1.0"/>

                                               

                                              These targets are object references. How would I pass them down (by ref or by val, I don't care which at this point) to the new custom component? Some kind of set/getProperty?

                                               

                                              I'm reading about creating custom components in my "Adobe Flex3 Training From The Source", but it does not discuss the property passing, unless I just missed it.

                                               

                                              Ben

                                              • 20. Re: Concept of Subroutine or Method in MXML?
                                                Flex harUI Adobe Employee

                                                You can probably get Jeffry's solution to work, but it, just like the way

                                                someone built these arrays out using concat will be slightly inefficient.

                                                The array sequence creates whole new copies of arrays that have to be

                                                instantiated and collected off the heap. Creating a whole new class to

                                                encapsulate part of a sequence so the original sequence has a sub-sequence

                                                may not be worth the effort.

                                                 

                                                This is why preprocessor macros came into existence and further messed up

                                                the world.  MXML and AS do not have official preprocessor phases.

                                                 

                                                Whether you start with MXML and convert to AS later is up to you, but it is

                                                roughly the equivalent of coding in 'C' and looking at the ASM output and

                                                working in ASM from there on out.  Some things are easier to code and

                                                maintain in a high-level markup language, other things are better done in

                                                lower layers of the stack.

                                                 

                                                For example, I use MXML binding {} syntax in prototypes, but if I need

                                                speed, I will later optimize those out to event listeners in AS.

                                                • 21. Re: Concept of Subroutine or Method in MXML?
                                                  benethridge Level 1

                                                  You can probably get Jeffry's solution to work...

                                                   

                                                  "Probably"?  He made it sound like it was a no-brainer, something out of a Flex beginner course, so either I'm still missing something or he is.  Probably me, since I'm the Flex newbie.

                                                   

                                                  I agree with you about preprocessor macros.

                                                   

                                                  Thanks also for the tip about after-coding the converted AS.

                                                   

                                                  Ben

                                                  • 22. Re: Concept of Subroutine or Method in MXML?
                                                    JeffryHouser Level 4

                                                    Any public variable can act as a property on a component.  You can also implement properties as get set methods.

                                                     

                                                    I would be very surprised if a Flex book does not cover creating a  component w/ properties; but I haven't read that one beyond the first  chapter.

                                                     

                                                    For quick and dirty purposes; you can do something like this in the component:

                                                     

                                                    <script>

                                                    public var initialImage : DisplayObject;

                                                    public var initialText: DisplayObject;

                                                    </script>

                                                     

                                                     

                                                    And pass it in from the main component like this:

                                                     

                                                    <ns1:MySubComponent initialImage="{initialImage}" initialText="{initialImage}" />

                                                     

                                                    Call me via http://www.asktheflexpert.com I can step you through this process in under an hour.

                                                    • 23. Re: Concept of Subroutine or Method in MXML?
                                                      benethridge Level 1
                                                      Any public variable can act as a property on a component.  You can also implement properties as get set methods.

                                                       

                                                      I would be very surprised if a Flex book does not cover creating a  component w/ properties

                                                       

                                                      None of my books show property creation, but googling it, I found one that does.  It appears to be setting it up pretty much as you say, and it says that MXML requires public variables to be properties passed between parent and child. See:

                                                      Adding Custom Properties and Methods to a Component

                                                       

                                                      in:

                                                       

                                                      http://www.wrox.com/WileyCDA/Section/Creating-Adobe-Flex-2-MXML-Components.id-306210.html

                                                       

                                                      I'll try it and let you all know how it went.

                                                       

                                                      Thanks.

                                                       

                                                      Ben

                                                      • 24. Re: Concept of Subroutine or Method in MXML?
                                                        JeffryHouser Level 4

                                                        I did a whole series of screencasts on creating Flex components.

                                                         

                                                        http://www.theflexshow.com/blog/index.cfm/Fifteen-Minutes-With-Flex

                                                         

                                                        It is a teach by example series; though.  We just cover things, such as properties, as there is a need for them in development.  I bet properties are covered early on, perhaps in the third episode:

                                                         

                                                        http://www.theflexshow.com/blog/index.cfm/2009/5/4/The-Flex-Show--Creating-Flex-Components --Episode-3-Dealing-with-the-DataProvider

                                                         

                                                        Also this episode of our previous series may help:

                                                         

                                                        http://www.theflexshow.com/blog/index.cfm/2008/8/6/The-Flex-Show--Fifteen-Minutes-With-Fle x--Episode-4--Creating-Component-Properties

                                                        • 25. Re: Concept of Subroutine or Method in MXML?
                                                          benethridge Level 1

                                                          I have this coded and it compiles ok but returns an error in AS at runtime:

                                                           

                                                          TypeError: Error #1034: Type Coercion failed: cannot convert incl::IncludeEmulator@700a479 to mx.effects.Effect.
                                                              at mx.effects::CompositeEffect/getChildrenTargets()[C:\autobuild\3.2.0\frameworks\projects\f ramework\src\mx\effects\CompositeEffect.as:400]
                                                              at mx.effects::CompositeEffect/captureStartValues()[C:\autobuild\3.2.0\frameworks\projects\f ramework\src\mx\effects\CompositeEffect.as:294]
                                                              at mx.core::UIComponent/commitCurrentState()[C:\autobuild\3.2.0\frameworks\projects\framewor k\src\mx\core\UIComponent.as:7163]
                                                              at mx.core::UIComponent/setCurrentState()[C:\autobuild\3.2.0\frameworks\projects\framework\s rc\mx\core\UIComponent.as:7113]
                                                              at mx.core::UIComponent/set currentState()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.a s:4361]
                                                              at EastRidgeSoftware/__btnRestart_click()[C:\Users\Ben\workspace\EastRidgeSoftware\src\EastR idgeSoftware.mxml:267]

                                                           

                                                          -----------------------------------------------------------------------------------------

                                                          Here is the associated code in the parent:

                                                           

                                                           

                                                                      <mx:Transition fromState="Designing" toState="Initial">
                                                                          <mx:Sequence>
                                                                              <!-- fadeout what is shown -->
                                                                              <mx:Fade duration="{fadeDuration}" targets="{[designingImage,designingText,designingText1,designingText2]}" alphaFrom="1.0" alphaTo="0.0"/>
                                                                              <mx:SetPropertyAction name="visible" targets="{[designingImage,designingText,designingText1,designingText2]}"/>

                                                           

                                                                              <inc:IncludeEmulator initialImage="{initialImage}" initialText="{initialText}" initialText1="{initialText1}" moveDuration="{moveDuration}"/>   
                                                                          </mx:Sequence>
                                                                      </mx:Transition>

                                                           

                                                          ...and the child:

                                                           

                                                          <?xml version="1.0" encoding="utf-8"?>
                                                          <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
                                                          <mx:Script>
                                                              <![CDATA[
                                                                  import mx.controls.Text;
                                                                  import mx.controls.Image;
                                                                  [Bindable]
                                                                  public var initialImage:Image;
                                                                  [Bindable]
                                                                  public var initialText:Text;
                                                                  [Bindable]
                                                                  public var initialText1:Text;
                                                                  public var moveDuration:Number;
                                                              ]]>
                                                          </mx:Script>
                                                                                  <!-- Fadein what should now be shown. -->
                                                                              <mx:Fade duration="1" targets="{[initialImage,initialText,initialText1]}" alphaFrom="0.0" alphaTo="1.0"/>
                                                                              <mx:SetPropertyAction name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                                                              <!-- Move it across the screen into reading position. -->
                                                                              <mx:Move duration="{moveDuration}" targets="{[initialText,initialText1,initialImage]}"/>

                                                           

                                                          </mx:Module>

                                                           

                                                          ------------------------------------------------------------------------------------------ ---------------------------------

                                                           

                                                          So it appears that a generic "Module" is not allowed, i.e. it wants a true "Component" one flavor or another.  Looking at the error above, my top guess is that AS cares about the component type, i.e. since it's running within a Transition, the only components allowed are Effects? Unfortunately, mx.effects.Effect is not in the list, i.e. not in <mx:> namespace.  I tried Canvas just for laughs, but same error, so I'm stuck.  Is there a way to inherit from Effect in MXML maybe?

                                                           

                                                          Ben

                                                          • 26. Re: Concept of Subroutine or Method in MXML?
                                                            jsd99 Level 3

                                                            Is there a particular reason you are set on using MXML for your combo effect?  You would have been done by now if you had done it in ActionScript, and it's not that much more code.

                                                             

                                                            MXML is great for creating UI's.  It's not a general purpose programming language, and trying to bend it to fit is just going to be a long-term headache.

                                                            • 27. Re: Concept of Subroutine or Method in MXML?
                                                              JeffryHouser Level 4

                                                              Don't use Module as the top level tag of your component.  Use sequence.  You're creating a custom component based on sequence.

                                                               

                                                              Modules are something different.

                                                              • 28. Re: Concept of Subroutine or Method in MXML?
                                                                benethridge Level 1

                                                                Hi, Jeffery. This didn't error, but it also didn't work, i.e. my image and text now don't appear.

                                                                 

                                                                Here is my new code:

                                                                 

                                                                Parent:

                                                                 

                                                                            <mx:Transition fromState="Designing" toState="Initial">
                                                                                <mx:Sequence>
                                                                                    <!-- fadeout what is shown -->
                                                                                    <mx:Fade duration="{fadeDuration}" targets="{[designingImage,designingText,designingText1,designingText2]}" alphaFrom="1.0" alphaTo="0.0"/>
                                                                                    <mx:SetPropertyAction name="visible" targets="{[designingImage,designingText,designingText1,designingText2]}"/>

                                                                 

                                                                                    <inc:IncludeEmulator initialImage="{initialImage}" initialText="{initialText}" initialText1="{initialText1}" moveDuration="{moveDuration}"/>   
                                                                                </mx:Sequence>
                                                                            </mx:Transition>
                                                                            <mx:Transition fromState="More" toState="Initial">
                                                                                <mx:Sequence>
                                                                                    <!-- fadeout what is shown -->
                                                                                    <mx:Fade duration="{fadeDuration}" targets="{[moreImage,moreText]}" alphaFrom="1.0" alphaTo="0.0"/>
                                                                                    <mx:SetPropertyAction name="visible" targets="{[moreImage,moreText]}"/>

                                                                 

                                                                                    <inc:IncludeEmulator initialImage="{initialImage}" initialText="{initialText}" initialText1="{initialText1}" moveDuration="{moveDuration}"/>   
                                                                                </mx:Sequence>
                                                                            </mx:Transition>

                                                                 

                                                                Child:

                                                                 

                                                                <?xml version="1.0" encoding="utf-8"?>
                                                                <mx:Sequence xmlns:mx="http://www.adobe.com/2006/mxml">
                                                                <mx:Script>
                                                                    <![CDATA[
                                                                        import mx.controls.Text;
                                                                        import mx.controls.Image;
                                                                        [Bindable]
                                                                        public var initialImage:Image;
                                                                        [Bindable]
                                                                        public var initialText:Text;
                                                                        [Bindable]
                                                                        public var initialText1:Text;
                                                                        public var moveDuration:Number;
                                                                    ]]>
                                                                </mx:Script>
                                                                                        <!-- Fadein what should now be shown. -->
                                                                                    <mx:Fade duration="1" targets="{[initialImage,initialText,initialText1]}" alphaFrom="0.0" alphaTo="1.0"/>
                                                                                    <mx:SetPropertyAction name="visible" targets="{[initialText,initialText1,initialImage]}"/>
                                                                                    <!-- Move it across the screen into reading position. -->
                                                                                    <mx:Move duration="{moveDuration}" targets="{[initialText,initialText1,initialImage]}"/>

                                                                 

                                                                </mx:Sequence>

                                                                ------------------------------------------------------------------------------------------ ---------------------

                                                                 

                                                                Note that the only thing I changed in the above from before was I made Module a Sequence instead.   I'm thinking we just put a Sequence within a Sequence, which threw off  AS, coz it was expecting an Effect?

                                                                 

                                                                Why do you say it needs to be a Sequence? Why not an Effect as per the error?

                                                                 

                                                                Ben

                                                                • 29. Re: Concept of Subroutine or Method in MXML?
                                                                  benethridge Level 1

                                                                  jsd99 wrote:

                                                                   

                                                                  Is there a particular reason you are set on using MXML for your combo effect?  You would have been done by now if you had done it in ActionScript, and it's not that much more code.

                                                                   

                                                                  MXML is great for creating UI's.  It's not a general purpose programming language, and trying to bend it to fit is just going to be a long-term headache.

                                                                   

                                                                  You'd need to read the top of this thread to fully understand. This isn't about combo effect. It's a more general problem.  MXML is missing what I consider to be an important feature of computer languages...any computer language.  We're trying to come up with a workaround which could be used as a general solution to keep the language "DRY".  This may turn out to be a headache as you say.

                                                                   

                                                                  Ben

                                                                  • 30. Re: Concept of Subroutine or Method in MXML?
                                                                    jsd99 Level 3

                                                                    I've read the entire thread and I still don't get your point.  MXML isn't a general purpose language.  It does have ways of repeating and modularizing things but they aren't going to work simply and naturally for what you want.  MXML + AS are like peanut butter & jelly.  You're trying to make peanut butter by adding nuts to jelly.  It won't work, and it will drive you nuts

                                                                    • 31. Re: Concept of Subroutine or Method in MXML?
                                                                      benethridge Level 1

                                                                      jsd99 wrote:

                                                                       

                                                                      MXML isn't a general purpose language. It does have ways of repeating and modularizing things but they aren't going to work simply and naturally for what you want.  MXML + AS are like peanut butter & jelly.  You're trying to make peanut butter by adding nuts to jelly.  It won't work, and it will drive you nuts

                                                                       

                                                                      I've been doing this a very long time, and I haven't been "driven nuts"...well, not yet :-)

                                                                       

                                                                      Over the years, I've discovered that if a language doesn't allow you to do things "simply and naturally", i.e. intuitively, it usually doesn't survive very long. So, instead of being driven nuts, I normally just back off the learning (the time investment) and look for a better emerging language.

                                                                       

                                                                      It is a bit ironic that XML has ways of avoiding this kind of repetition "simply and naturally" that MXML apparently does not.

                                                                       

                                                                      Rather than saying that MXML is not a "general purpose language", I'd just say it's not a very good language.  I mean, who cares whether it's "general purpose" or not. We're using the language to solve a business problem.  If we have to write a million lines of code with it and 10% of those lines are duplicated due to (a) unreasonable (aka "normal") deadline constraints (b) relatively inexperienced coders and (c) a lack of some "simple and natural" feature of the language, it didn't really matter whether it was general purpose or not. It's still going to cost our company a lot of extra money to maintain the dupes...not to mention the poor programmers who get that fun assignment.

                                                                       

                                                                      I'm writing all this, hoping that someone at Adobe will read it and make it a better language, so I don't have to go learn Silverlight or some such. :-)

                                                                       

                                                                      Ancient, ancient rule: Never ever duplicate significant chunks of code.  Some shops standardize on no more than 3 lines duplicated, which, though I think that's pushing it, I could see a case for.

                                                                       

                                                                      Ben

                                                                      • 32. Re: Concept of Subroutine or Method in MXML?
                                                                        levancho Level 3

                                                                        MXML is just a convinience in Flex nothing less or more, its convinient approach  mostly for design purposes,

                                                                        and it is an additional layer on top of ActionScript, because at the and of the day before things turn  binary they get all converted to ActionScript

                                                                        IMHO, one should use as little MXML as possible and only for Visual representations. so fromt aht perspective all is good 

                                                                        that is just my opinion, does not have to be correct

                                                                        • 33. Re: Concept of Subroutine or Method in MXML?
                                                                          benethridge Level 1

                                                                          levancho wrote:

                                                                           

                                                                          MXML is just a convinience in Flex nothing less or more, its convinient approach  mostly for design purposes,

                                                                          and it is an additional layer on top of ActionScript, because at the and of the day before things turn  binary they get all converted to ActionScript

                                                                          IMHO, one should use as little MXML as possible and only for Visual representations. so fromt aht perspective all is good 

                                                                          that is just my opinion, does not have to be correct

                                                                           

                                                                          I agree with you. I think it's fine for storyboarding and mockups and such.

                                                                           

                                                                          My beef with MXML is that the flex books (or at least the 3 popular ones I have) are touting it as a full-featured language and they're using it heavily.

                                                                           

                                                                          Based on your comment (and others like it) I'm about ready to dump MXML and just code in pure ActionScript. Would that be a reasonable alternative? or is MXML doing a lot of wiring (config files, etc) behind the scenes that I'd now have to hand-code?

                                                                           


                                                                          Ben

                                                                          • 34. Re: Concept of Subroutine or Method in MXML?
                                                                            jsd99 Level 3

                                                                            benethridge wrote:

                                                                             

                                                                            levancho wrote:

                                                                             

                                                                            MXML is just a convinience in Flex nothing less or more, its convinient approach  mostly for design purposes,

                                                                            and it is an additional layer on top of ActionScript, because at the and of the day before things turn  binary they get all converted to ActionScript

                                                                            IMHO, one should use as little MXML as possible and only for Visual representations. so fromt aht perspective all is good 

                                                                            that is just my opinion, does not have to be correct

                                                                             

                                                                            I agree with you. I think it's fine for storyboarding and mockups and such.

                                                                             

                                                                            My beef with MXML is that the flex books (or at least the 3 popular ones I have) are touting it as a full-featured language and they're using it heavily.

                                                                             

                                                                            Based on your comment (and others like it) I'm about ready to dump MXML and just code in pure ActionScript. Would that be a reasonable alternative? or is MXML doing a lot of wiring (config files, etc) behind the scenes that I'd now have to hand-code?

                                                                             

                                                                            unfortunately i think your books have led you astray, but it's not really that surprising - they want to sell books so they tout things like "super easy, drag n drop, no programming required".  for a completely trivial application, you might be able to get away with pure MXML, but for anything remotely sophisticated, it won't be adequate, or the contortions required to make it work would be more trouble than its worth.

                                                                             

                                                                            regarding your suggestion to "just code in pure ActionScript", I wouldn't be that dogmatic.  MXML has its uses.  Its strength is in designing/laying out UI elements.  As long as you make that the primary focus, it works very well.  But you know, you've got two tools in the toolbox (MXML & AS).  Use the one that's appropriate to the task at hand.  In my apps, the UI classes are about 50/50 MXML/AS, then there are various "support" classes which are pure AS.  Sure you could create and style a DataGrid with AS, but MXML+CSS makes it much easier.

                                                                            • 35. Re: Concept of Subroutine or Method in MXML?
                                                                              JeffryHouser Level 4

                                                                              You're looking for programming features in something that isn't a programming language.

                                                                               

                                                                              MXML is a markup language, more akin to HTML than JavaScript.  Not being able to encapsulate code has not harmed HTML all that much.

                                                                              • 36. Re: Concept of Subroutine or Method in MXML?
                                                                                levancho Level 3

                                                                                I really like mxml to visualize and layour pages as preliminary

                                                                                Besides that I don't see any added value 

                                                                                 

                                                                                 

                                                                                 

                                                                                -- Sent from my Palm Pre

                                                                                On Mar 18, 2010 8:48 PM, benethridge &lt;forums@adobe.com&gt; wrote:

                                                                                • 37. Re: Concept of Subroutine or Method in MXML?
                                                                                  Flex harUI Adobe Employee

                                                                                  Web-site developers don't really need HTML either right?  You can just

                                                                                  insert enough Javascript to write to the document and get what you want.

                                                                                   

                                                                                  But few folks do that because HTML provides lower cost way of laying out and

                                                                                  maintaining your ui than all that JS.

                                                                                   

                                                                                  What feature does XML have to eliminate repetition?

                                                                                  • 38. Re: Concept of Subroutine or Method in MXML?
                                                                                    levancho Level 3

                                                                                    I think, right now dhtml has advanced so much that it has became debatable ,'to hml or not to html'  for example: js libraries e.g: yui,offer full set of components, custom event model etc...  that ar only maintainable through js, further more, many new webapps are almost completly built from js, that does not mean html is useless it just js has become more than just 'function here or there' of course whole dhtml model is still far from bein on the same height as flex but that's a dif discusaion topic.

                                                                                    On the other hand, mxml give invaluable advantage to pixel perfectly layout application, beyond that it does not really have any real value, including all those mxml tags for creating remote objects, arays, and services, they sometimes give more headache .... So mxml definatwly have room in a developer toolbox

                                                                                    That is my opinion on that

                                                                                    Regards

                                                                                    Levan

                                                                                     

                                                                                     

                                                                                    -- Sent from my Palm Pre

                                                                                    On Mar 18, 2010 11:46 PM, Flex harUI &lt;forums@adobe.com&gt; wrote:

                                                                                     

                                                                                    Web-site developers don't really need HTML either right?  You can just

                                                                                     

                                                                                    insert enough Javascript to write to the document and get what you want.

                                                                                     

                                                                                     

                                                                                     

                                                                                    But few folks do that because HTML provides lower cost way of laying out and

                                                                                     

                                                                                    maintaining your ui than all that JS.

                                                                                     

                                                                                     

                                                                                     

                                                                                    What feature does XML have to eliminate repetition?

                                                                                    • 39. Re: Concept of Subroutine or Method in MXML?
                                                                                      benethridge Level 1

                                                                                      What feature does XML have to eliminate repetition?

                                                                                       

                                                                                      Include files:

                                                                                       

                                                                                      http://www.w3schools.com/schema/el_include.asp

                                                                                       

                                                                                      Ben

                                                                                      1 2 Previous Next