Welcome Developers!

in

Welcome!

in

Example: Flash/Flex 2- AS3

Last post 08-31-2010 1:17 PM by Joel. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-24-2008 11:10 PM

    Example: Flash/Flex 2- AS3

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
        <mx:HTTPService
            id="viewerProfileRequest"
            result="viewerProfileRequest_OnResult(event)"
            fault="viewerProfileRequest_OnFault(event)"
            useProxy="false" />
        <mx:HTTPService
            id="friendsRequest"
            result="friendsRequest_OnResult(event)"
            fault="friendsRequest_OnFault(event)"
            useProxy="false" />
       
        <mx:Panel title="MySpace Flex App" width="441" height="326" paddingLeft="10" paddingRight="10">
            <mx:Label text="" fontWeight="bold"/>
            <mx:TabBar dataProvider="mainViewStack">
            </mx:TabBar>
            <mx:ViewStack width="400" height="150" id="mainViewStack">
                <mx:Canvas label="Output" width="400" height="150" id="outputView">
                    <mx:TextArea x="0" y="0" width="100%" height="100%" id="outputTextArea"/>
                </mx:Canvas>
                <mx:Canvas label="Profile" width="400" height="150" id="profileView">
                    <mx:Panel x="0" y="0" width="100%" height="100%" layout="absolute" title="Viewer Profile">
                        <mx:Image x="10" y="10" width="92" height="90" id="profileImage" source="{profileXml.apiNS::imageuri}"/>
                        <mx:Label x="121" y="10" text="{profileXml.apiNS::userid}" id="userIdLabel"/>
                        <mx:Label x="121" y="36" text="{profileXml.apiNS::displayname}" id="displayNameLabel"/>
                        <mx:Label x="121" y="62" text="{profileXml.apiNS::weburi}" id="webUriLabel"/>
                    </mx:Panel>
                </mx:Canvas>
                <mx:Canvas label="My Friends" width="400" height="150" id="friendsView">
                    <mx:DataGrid x="0" y="0" width="100%" height="100%" dataProvider="{userXml}">
                        <mx:columns>
                            <mx:DataGridColumn headerText="userid">
                              <mx:itemRenderer>
                                <mx:Component>
                                    <mx:Label text="{data.*::userid}" />
                                </mx:Component>
                              </mx:itemRenderer>
                            </mx:DataGridColumn>
                            <mx:DataGridColumn headerText="displayname">
                              <mx:itemRenderer>
                                <mx:Component>
                                    <mx:Label text="{data.*::displayname}" />
                                </mx:Component>
                              </mx:itemRenderer>
                            </mx:DataGridColumn>
                            <mx:DataGridColumn headerText="imageuri">
                              <mx:itemRenderer>
                                <mx:Component>
                                    <mx:Image source="{data.*::imageuri}" width="20" height="20" />
                                </mx:Component>
                              </mx:itemRenderer>
                            </mx:DataGridColumn>
                        </mx:columns>
                    </mx:DataGrid>               
                </mx:Canvas>
            </mx:ViewStack>
            <mx:TextArea x="20" y="185" width="400" height="20" visible="true" id="osTokenTextArea"/>
            <mx:HBox width="100%">
                <mx:LinkButton label="Get Viewer Profile" id="profileLinkButton"/>
                <mx:LinkButton label="Get Friends" id="friendsLinkButton"/>
                <mx:LinkButton label="Get Info" id="urlLinkButton"/>
                <mx:LinkButton label="Clear" id="clearLinkButton"/>
            </mx:HBox>
        </mx:Panel>

           
        <mx:Script>
            <![CDATA[
            import flash.events.MouseEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
           
             public static var OPEN_SOCIAL_TOKEN:String = "opensocial_token";
            public static var OPEN_SOCIAL_MODE:String = "opensocial_surface";
            public static var OPEN_SOCIAL_KEY:String = "opensocial_consumer_key";
            public static var DETAIL_TYPE:String = "detailtype";
           
            public static var NS_API_V1:String = "api-v1.myspace.com";
            public static var NS_XSI:String = "http://www.w3.org/2001/XMLSchema-instance";
            public static var NS_XSD:String = "http://www.w3.org/2001/XMLSchema";
           
            public static var URL_ROOT_API:String = "http://api.msappspace.com/opensocial";
           
            [Bindable]
            public var friendsXml:XML;
            [Bindable]
            public var userXml:XMLList;   
            [Bindable]
            public var profileXml:XML;

            public var apiNS:Namespace;
           
            [Bindable]
            public var os_token:String;
           
            public function init():void {
                apiNS = new Namespace(NS_API_V1);
                os_token = getOpenSocialToken();
               
                profileLinkButton.addEventListener(MouseEvent.CLICK, profileLinkButton_OnClick);
                friendsLinkButton.addEventListener(MouseEvent.CLICK, friendsLinkButton_OnClick);
                urlLinkButton.addEventListener(MouseEvent.CLICK, urlLinkButton_OnClick);
                clearLinkButton.addEventListener(MouseEvent.CLICK, clearLinkButton_OnClick);
               
                osTokenTextArea.text = os_token;
            }
           
            public function getOpenSocialToken():String {
                var token:String = Application.application.parameters[OPEN_SOCIAL_TOKEN];
                           
                return token;
            }
           
            public function getOpenSocialSurface():String {
                var mode:String = Application.application.parameters[OPEN_SOCIAL_MODE];
               
                if (mode == null) {
                    mode = "canvas";
                }
               
                return mode;
            }
           
            public function getDetailType():String {
                var detail:String = Application.application.parameters[DETAIL_TYPE];
               
                if (detail == null) {
                    detail = "BASIC";
                }
               
                return detail;
            }
           
            private function clearOutput():void {
                outputTextArea.text = "";           
            }
           
            private function getViewer():void {
                var serverUrl:String = "http://api.msappspace.com/opensocial/v1";
                var viewerUrl:String = "/VIEWER";
                var profileUrl:String = "/profile.XML";
                var token:String = osTokenTextArea.text;
                var surface:String = "canvas";
                var detail:String = "BASIC";

                viewerProfileRequest.url = serverUrl + viewerUrl + profileUrl + "?";
                viewerProfileRequest.url += OPEN_SOCIAL_TOKEN + "=" + token;
                viewerProfileRequest.url += "&" + OPEN_SOCIAL_MODE + "=" + surface;
                viewerProfileRequest.url += "&" + DETAIL_TYPE + "=" + detail;
                viewerProfileRequest.resultFormat = "e4x";
                viewerProfileRequest.send();
            }
           
            private function getFriends():void {
                var serverUrl:String = "http://api.msappspace.com/opensocial/v1";
                var viewerUrl:String = "/VIEWER";
                var friendsUrl:String = "/friends.XML";
                var token:String = osTokenTextArea.text;
                var surface:String = "canvas";
                var detail:String = "BASIC";

                friendsRequest.url = serverUrl + viewerUrl + friendsUrl + "?";
                friendsRequest.url += OPEN_SOCIAL_TOKEN + "=" + token;
                friendsRequest.url += "&" + OPEN_SOCIAL_MODE + "=" + surface;
                friendsRequest.url += "&" + DETAIL_TYPE + "=" + detail;
                friendsRequest.resultFormat = "e4x";
                friendsRequest.send();           
            }
           
            public function friendsRequest_OnResult(event:ResultEvent):void {
                friendsXml = event.result as XML;
                userXml = friendsXml.apiNS::friends.apiNS::user as XMLList;
                outputTextArea.text = friendsXml.toString();
            }
           
            public function friendsRequest_OnFault(event:FaultEvent):void {
                Alert.show(event.fault.message, "Could not call REST API");
            }
               
            public function viewerProfileRequest_OnResult(event:ResultEvent):void {
                profileXml = event.result as XML;
                outputTextArea.text = profileXml.toXMLString();
            }
                   
            public function viewerProfileRequest_OnFault(event:FaultEvent):void {
                Alert.show(event.fault.message, "Could not call REST API");
            }
                       
            public function profileLinkButton_OnClick(e:MouseEvent):void {
                getViewer();
            }
                       
            public function friendsLinkButton_OnClick(e:MouseEvent):void {
                getFriends();
            }
                   
            public function urlLinkButton_OnClick(e:MouseEvent):void {
                clearOutput();
               
                for (var i:String in Application.application.parameters)
                {
                   outputTextArea.text += i + ":" + Application.application.parameters[i] + "\n";
                }
            }
           
            public function clearLinkButton_OnClick(e:MouseEvent):void {
                clearOutput();
            }
            ]]>
        </mx:Script>

    </mx:Application>

  • 02-25-2008 12:33 AM In reply to

    • Dave
    • Top 25 Contributor
    • Joined on 02-05-2008
    • Posts 137

    Re: Example: Flash/Flex 2- AS3

    I'll take a closer look at the code in the morning, but I just wanted to say *thank you*!

    I really appreciate the example, and the fact that you worked on it over the weekend and posted it late on a Sunday.  Thanks! 

  • 02-25-2008 5:55 AM In reply to

    Re: Example: Flash/Flex 2- AS3

     Viphak,

    tried it - it works like a charm! Thanks a lot for the example, that's great!!

     Cheers

    Michael 

  • 02-25-2008 5:59 AM In reply to

    • Giri
    • Top 500 Contributor
    • Joined on 02-05-2008
    • Posts 12

    Re: Example: Flash/Flex 2- AS3

    Viphak,

     Thank you for the example. Works like a charm!

     -giri

  • 09-24-2009 11:05 PM In reply to

    Re: Example: Flash/Flex 2- AS3

    Viphak,

     

    Please tell me the steps to run this code?

     

    -Nilakshi

  • 10-05-2009 2:03 PM In reply to

    Re: Example: Flash/Flex 2- AS3

    Hey Nilakshi,

    You need Flex installed. Its just a mxml file. Paste the whole thing and run =)

    -V
    Filed under:
  • 10-23-2009 12:01 AM In reply to

    Re: Example: Flash/Flex 2- AS3

    Hi Viphak,

     

    I hv create a applicatiobn in flex n pasted ur code, the app is working bt im not getting the profile details, friend liston click of buttons,...

    can u plz help me...

     

    this is the error im getting...

    faultCode:Server.Error.Request faultString:'HTTP request error' faultDetail:'Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://api.msappspace.com/opensocial/v1/VIEWER/profile.XML?opensocial_token=496060003&opensocial_surface=canvas&detailtype=BASIC"]. URL: http://api.msappspace.com/opensocial/v1/VIEWER/profile.XML?opensocial_token=496060003&opensocial_surface=canvas&detailtype=BASIC'

     

    thanx in Advance...

  • 08-27-2010 12:46 AM In reply to

    • Gopi
    • Not Ranked
    • Joined on 08-03-2010
    • Posts 1

    Problem in loading profile and other data

     Hi,

     

    Can you explain me a detailview of how to create OPEN_SOCIAL_TOKEN, and  OPEN_SOCIAL_KEY in myspace for flex application.

     

    Thank you in advance

    Gopi Krishna E.

  • 08-31-2010 1:17 PM In reply to

    Re: Problem in loading profile and other data

     The param you refer to as opensocial token is reall the oauth access token that is assigned to a specific user. The key is the consumer_key which gets automatically assigned to you once you create an app. Are you trying to create an onsite or offsite (MyspaceID) application?

     

    thanks,

    Joel

Page 1 of 1 (9 items)