views:

368

answers:

2

I have Flex application requiring to filter users depending on there database groups. Depending on which group they are, the're is a config.xml file that is use to populate the swf.

Here is how I figure how to do this :
1. The client comes to a .aspx page with a form requiring a username and a password.
2. On the server side I confirm the user credential
3. Once the username/password is valid I redirect to the mxml file with the config.xml file in the html headers (post).

My problem comes when I need to get the post data from the http request. Let's say I have this code :

<mx:Application initialize="init()">

    <mx:Script>
        <![CDATA[
            private function init():void
            {
                // get the post data here
            }

            /* More code here */
        ]]>
    </mx:Script>

</mx:Application>

How do I get the post data on the init() function.

Thank you.

A: 

I don't think it's possible to get the POST data, but others might have a way. An alternative solution would be:

  1. User logs in: login.aspx
  2. User directed to Flash content: content.html embedding content.swf
  3. Flash requests config.xml from server: content.swf makes HTTP request for config.xml.aspx
  4. Server provides user's configuration in config.xml.aspx

In your init() function, you'd make the URLLoader request to get the configuration, and you'd do the configuration in the Event.COMPLETE handler.

Another possibility is to use HTTP cookies--not handled natively by Flash, but you can get to them via Javascript--see this CookieUtil class.

Michael Brewer-Davis
The thing is that I need the correct config.xml file path at runtime, I need to pass it as an argument or something.
Frank
Why can't the server resolve the correct path on the `config.xml.aspx` call, and respond with the appropriate data?
Michael Brewer-Davis
In the swf I have a parameter that represent the path to the config.xml file. Depending on the credentials of the user I must change this path to the correct xml file. Do you see any other options?
Frank
If the path is a server-side path (i.e., part of a URL the SWF will use), I'm sticking with having one server ASP page serve both files and decide between them based on credentials. That's essentially how we do it with our Flex app.You could also pass the path only (or enough info to generate the path) as a GET parameter, and then read it from the URL.
Michael Brewer-Davis
Yes. But this way the user knows what the config file is which might be a security problem.
Frank
+1  A: 

For those that would be interested, I've found some ressources on the Adobe Flex 3 Ressource center.

Basically there is no current way to pass data with the POST method. You can either add the parameters at the end of you swf url (GET method) as shown here : http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_5.html#245869

The other way is to embed them in the page with the flashVars method shown here : http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html#229997

If you still wonder, how I'll manage to do this if you run to in the same situation. Here is my idea (feel free to share if you have different vision) :

1.User logs in login.aspx
2.Depending on the credentials of the users the server side code modify the index.html file to embed the correct xml file in the flash object.
3.With the FlashVars method, I get back the xml file path and job done!

If you ever run in a similar situation and need help contact me.

Frank