jump to navigation

Howto: Add Basic Authentication Header to HTTPService July 4, 2008

Posted by Mayank in actionscript, flex.
Tags: , , , ,
7 comments

HTTPService in flex supports addition of headers as required. Follow the steps below to add authetication headers to your HTTPService when accessing a service protected by basic authentication.

<mx:Script>
    <![CDATA[
        import mx.utils.Base64Encoder;
        import mx.controls.Alert;
        
        private var baseUrl:String = "http://phprestsql.sourceforge.net/tutorial/user";
        private var auth:String = "p126371rw:demo";
        
        private function init():void{
            var encoder : Base64Encoder = new Base64Encoder();
            encoder.encode(auth);
            userService.headers["Authorization"] = "Basic " + encoder.toString();
            deleteUser();
        }
    ]]>
</mx:Script>
	

Enjoyyy!!!

Howto: Organise custom components in Flex? August 9, 2007

Posted by Mayank in flex.
1 comment so far

Most of the material on custom components in flex talks about their creation and their use within flex applications. As the number of components begin to grow one begins to feel the need for organising them in subfolders.

To use a custom component in a Flex application we usually add an attribute to the mx:Application tag:

<mx:Application
xmlns:local="*"
...
>

and then use the components as

<local:myComponent/>

I recently solved the mystery behind this attribute :). If you would like to organise the components into subfolders, then create a folder as desired and while setting the namespace attribute in the mx:Application tag set it like this:


<mx:Application
xmlns:myComponents1="subfolder1.*"
...
>

To access the components you would use

<myComponents1:yourComponents/>

You can create additional folders and include their namespaces too :).

<mx:Application
xmlns:myComponents2="subfolder2.*"
...
>

To take this a step further, you could nest your folders to mimick the way your organise your java packages:

Create sub1, and then sub2 under sub1

To use components under sub1 you could place a namespace declaration like:


<mx:Application
xmlns:s1="sub1.*"
...
>

and then to include sub2 components you would declare another namespace:


<mx:Application
xmlns:s2="sub1.sub2.*"
...
>

Hope that helps you in organising your custom flex components.

Happy Flex-ing! 🙂