10 Replies Latest reply on Jul 30, 2009 3:41 PM by Baal Bebb

    Can Flex do this?

    Baal Bebb

      Hello,

      I'm trying to develop an application in Flash that seems impossible.I'm wondering if perhaps Flex would be more appropriate for my needs. Here's what I want to be able to do:

       

      User inputs data into an XML file (or ideally a form that updates an XML file) and uses this XML file to GENERATE a flash SWF whose data and variables depends on the values in the XML file.

       

      Finally I want this SWF file to be a standalone file (that doesn't depend on the XML file at runtime) and can be uploaded to a server and run without the XML file that generated it.

       

      Is this possible?

       

      -sage

        • 1. Re: Can Flex do this?
          Gregory Lafrance Level 6

          I don't think I fully understand your scenario. User generates an XML file by entering data in a form, but you also say the resultant SWF should not depend on the XML file, though it is generated from that XML file (== mild confusion).

           

          You can't generate a SWF on the fly, but you can have a Flex app that generates UI based on what's in an XML file.

           

          Please clarify what your app should do, and the dependencies involved.

          • 2. Re: Can Flex do this?
            Baal Bebb Level 1

            Let me try again:

             

            The SWF file that is generated from the XML file should be standalone. Once it has been generated by the XML file it no longer needs the XML file at all. So, in essence, the XML file is used to create the SWF file after which the XML file is no longer necessary and can be deleted forever. The resultant SWF file could then be uploaded to the server and would have all the data that come from that XML File (radio button labels, text, etc.). The XML file - no longer being needed - would not need to be uploaded to the server.

            Does that make more sense?

            Also, is it possible for users to create these SWF files without having access to Flash or Flex builder?
            • 3. Re: Can Flex do this?
              Gregory Lafrance Level 6

              I don't think what you are describing is possible with Flex. You can have a Flex app that generates the UI from an XML file at runtime, but the XML file is necessary, and a SWF file is not generated. The SWF file is already on the user's machine (it is the SWF for the Flex app).

               

              An XML file is not strictly necessary. The user could interact with the Flex app UI, make selections and choices, and then that Flex app could re-render based on the user's selections and choices.

               

              If this post answered your question or helped, please mark it as such.

              • 4. Re: Can Flex do this?
                JeffryHouser Level 4

                If I had to theorize, I bet it is possible if you have some kind of server side piece involved.

                 

                Based on the user's input in the form you want to:

                 

                a) Generate your own MXML / ActionScript code

                b) Send that MXML / AS code to the command line Flex Compiler, which will then return a resulting swf

                c) Distribute the SWF as you wish

                 

                I can't envision the use case for doing this, though.  It is not a traditional approach in any sense.

                • 5. Re: Can Flex do this?
                  mcgraphix

                  If I understand this correctly, you want a Flex/Flash application that can compile a separate SWF that uses the XML file? You can't compile a SWF directly from Flash/Flex but what you could do is this:

                  1. create a Flex application that knows how to handle the XML file that is going to be created (probably using the <mx:XML /> tag to load it at compile time), but don't compile this application yet.
                  2. use an AIR application to generate the XML file, store it to the file system in the project directory of the flex app you created in step 1
                  3. then use something like Merapi to call from the AIR application out to the MXML compiler to compile the Flex app from step 1 which will use the XML file from step 2
                  4. The result will be the SWF file that has your custom XML compiled in

                   

                  There are kind of a lot of moving parts to this and like the previous post said, I can't imagine why you would want to do this. It would be easier to just create your shell SWF that loads the XML at runtime.

                  • 6. Re: Can Flex do this?
                    Baal Bebb Level 1

                    Ok, well here's an example of the kind of thing we'll be creating:

                     

                    http://distance.uaf.edu/projects/flash-tutors/sequencing-tutor.html

                     

                    However, we will be creating MANY of them and we'd like to be able to just input some data in a form, have it update an XML file, and then have that XML file create a new SWF file that has different questions, hints, content, etc. instead of having to manually create 100's of these things by moving radio buttons around manually in Flash, changing labels, etc. Since they will all essentially LOOK the same I was hoping we could create or use an application to automate some of this. There has got to be a faster way to do this I'm thinking.

                     

                    Your ideas? Am I making any sense?

                    • 7. Re: Can Flex do this?
                      mcgraphix Level 1

                      You could definitely do that using the approach I described but you don't have to. What would be better is to create your Flash or Flex app in a way that it will be smart enough to layout the questions, hints, widgets, etc. based on information in the XML. Then you could deploy a single SWF file and many (hundreds or more) of XML files. So you would always be loading the same SWF but it would then load the correct XML that would have all the information it needs to render what you want. I have used this approach many times and it has its benefits. The most significant is that if you need to change your app to fix a bug or to update the look and feel you only need to update and publish a single new SWF rather than hundreds. Also if your users are going to be accessing multiple surveys, they would load faster beause each additional one only requires that they download the XML instead of an additional SWF

                      • 8. Re: Can Flex do this?
                        Baal Bebb Level 1

                        Interesting... I don't suppose you know of any good tutorials out there I could read/play around with? Or what keywords I should use to search for such a thing?

                         

                        If I used this approach I would still need to upload an XML file to go with the SWF template correct?

                         

                        Because my ultimate solution would be to find away to use an XML file to CREATE a SWF file (based on a template) that would then be standalone from the XML file and not need it anymore.

                         

                        -sage

                        • 9. Re: Can Flex do this?
                          RWinscot

                          What you are describing is how Flex 1.5 was architected and isn't a far stretch. In order to get this working... you need to be thinking in Flex and mxml. Given the following template...

                           

                          <?xml version="1.0" encoding="utf-8"?>
                          <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
                              <mx:Label x="10" y="272" id="lblResponse"/>

                           

                              <!-- responses -->

                           

                              <mx:Label x="10" y="10" text="$qStimulus" id="lblStimulus"/>
                          </mx:Module>

                           

                          1) Search and replace your $qStimulus (the question)

                          2) Flow in your items in the <!-- responses --> area like...

                           

                          <mx:CheckBox x="89" y="152" label="This is correct." click="lblResponse.text='You are correct!';"/>
                          <mx:CheckBox x="89" y="122" label="This is incorrect." click="lblResponse.text='You are incorrect';"/>

                           

                          3) Save as whatever filename you like

                          4) Hit the mxmlc (compiler) and compile it to a module for runtime loading

                           

                          Cheers,

                           

                          Rick Winscot

                          1 person found this helpful
                          • 10. Re: Can Flex do this?
                            Baal Bebb Level 1

                            Wow, that's awesome. That sounds about right. And once you've used mxml to create the SWF file you don't need to upload the mxml file to the server because it compiles the code into a standalone SWF?

                             

                            Amazing - I'm ordering it.