Pages

Thursday, May 3, 2012

How to connect Twitter in Flash ActionScript3.0



Here we i'll look at. How to get twitter user details.



var myXMLLoader:URLLoader = new URLLoader();

//--------add event for xml loader--------//
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
myXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, processError);
myXMLLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, processError);




tweet_btn.addEventListener(MouseEvent.CLICK,onTweet);
getDetails_btn.addEventListener(MouseEvent.CLICK,onGetDetails);
twitterId_txt.addEventListener(FocusEvent.FOCUS_IN,onFocus);


detail_mc.gotoAndStop(1);

//------function for tweet your status----//
function onTweet(event:MouseEvent):void
{
navigateToURL(new URLRequest('http://twitter.com/home?status='+encodeURIComponent(tweetMsg_txt.text)),'_blank');
}


function onFocus(event:FocusEvent):void
{
twitterId_txt.removeEventListener(FocusEvent.FOCUS_IN,onFocus);
twitterId_txt.text="";
}


function processError(event:Event):void
{
detail_mc.gotoAndStop(4);
getDetails_btn.mouseEnabled=true;
}

//------function for fetch twitter user details-----//
function onGetDetails(event:MouseEvent):void
{
if(twitterId_txt.length>0)
{
detail_mc.gotoAndStop(2);
getDetails_btn.mouseEnabled=false;
myXMLLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline.xml?screen_name="+twitterId_txt.text));
}
}


//-----------display twitter details-------//
function processXML(e:Event):void{
detail_mc.gotoAndStop(3);
getDetails_btn.mouseEnabled=true;
var myXML:XML = new XML(e.target.data);
trace(myXML);
if(myXML.status.length()>0)
{
detail_mc.follow_btn.addEventListener(MouseEvent.CLICK,onFollow);
detail_mc.img_mc.source=myXML.status[0].user.profile_image_url;
detail_mc.name_txt.text=myXML.status[0].user.name;
detail_mc.location_txt.text=myXML.status[0].user.location;
detail_mc.description_txt.text=myXML.status[0].user.description;
detail_mc.scrName_txt.text=myXML.status[0].user.screen_name;
detail_mc.followers_txt.text=myXML.status[0].user.followers_count;
detail_mc.friends_txt.text=myXML.status[0].user.friends_count;
}
else
detail_mc.gotoAndStop(4);
}

//--------call follower link-----------//
function onFollow(e:MouseEvent):void{
navigateToURL(new URLRequest("http:///twitter.com/"+detail_mc.scrName_txt.text));
}


Thank you

...CHeeRS...




                                 
                                    SourceFile

0 comments:

Post a Comment