Hey guys, I’m trying to integrate the twitter API into my project, followed a tutorial step by step and keep getting this error! It’s driving me crazy because I don’t have the knowledge to sort it out… if anyone could take a quick look and let me know what’s wrong then it would be hugely appreciated!
It's working!TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main/displayInfo()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Here’s my code from my Main Class:
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.MovieClip
import flash.events.Event;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
public class Main extends MovieClip
{
public var content_txt:TextField;
public var posted_txt:TextField;
public var info_txt:TextField;
public var name_txt:TextField;
private static const USERNAME:String = "BBCCLICK";
private static const URL:String = "http://preview.fladev.com/how-to-build-a-flash-actionscript-3-0-twitter-widget/proxy.php?url=";
private static const REQUEST:String = URL + USERNAME;
private var urlLoader:URLLoader;
private var xml:XML;
private var loader:Loader;
private var num:Number = 1;//display first post info, you can use also ?count=5
public function Main()
{
trace( "It's working!" );
urlLoader = new URLLoader();
urlLoader.load(new URLRequest(REQUEST));
urlLoader.addEventListener(Event.COMPLETE, displayInfo);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurity);
}
private function onSecurity(e:SecurityErrorEvent):void
{
}
private function displayInfo(e:Event):void
{
xml = new XML(e.target.data);
//get status updates - Most recent first
content_txt.htmlText = getContent(1) + getContent(2)+ getContent(3) + getContent(4);
//trace(xml);
//show some info about the user
info_txt.text = "Followers: " + xml.status[num].user.followers_count + "; " + "Following " + xml.status[num].user.friends_count + "; " + "Tweets " + xml.status[num].user.statuses_count + ";";
//display the user account
name_txt.text = xml.status[num].user.screen_name;
//create a loader for picture
loader = new Loader();
loader.load(new URLRequest(xml.status[num].user.profile_image_url));
addChildAt(loader, 1);
loader.x = 74;
loader.y = 50;
}
private function getContent(num:Number) {
//show just month, day and hour
var posted:String = xml.status[num].created_at;
var content:String = "<font color='#224466'><a href=" + '"http://twitter.com/' + USERNAME + "/statuses/" + xml.status[num].id + '" target="_blank">' + xml.status[num].text + "</a></font><br/><font size='9'>" +"Posted on: " + posted.substr(0, posted.length - 11) + "; " + "From: " + xml.status[num].source + "</font><br/><br/>";
//return all info
return content;
}
}
}
And the code from the php:
<?php$name = $_GET['url'];$url = 'http://twitter.com/statuses/user_timeline.xml?screen_name=';
$url .= $name;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);curl_close ($ch);$string = ob_get_contents();
$content = ob_end_clean();
//$content = get_content("");echo $string;?>