0
import flash.display.Sprite;
0
import flash.display.DisplayObject;
0
+ import flash.display.LoaderInfo;
0
import skins.GithubBadgeSkin;
0
import com.adobe.serialization.json.JSON;
0
+ import flash.external.ExternalInterface;
0
Data looks pretty much like this:
0
@@ -26,15 +29,31 @@ package {
0
public class GithubBadge extends Sprite {
0
private var _gw:Gateway;
0
private var _pl:ProjectList;
0
+ private var _user:String;
0
public function GithubBadge() {
0
+ addExternalInterface();
0
+ user = getParams().gitUser;
0
- _pl = new ProjectList();
0
+ this.requestData(user);
0
- this.requestData('evilchelu');
0
+ private function addExternalInterface():void {
0
+ if ( ExternalInterface.available ) {
0
+ ExternalInterface.addCallback("requestData",requestData);
0
+ private function getParams():Object {
0
+ return LoaderInfo(this.loaderInfo).parameters;
0
private function onDataLoaded(e:GatewayEvent):void {
0
@@ -42,23 +61,23 @@ package {
0
private function displayProjectList(user:Object):void {
0
- _pl.setHeader({image: SpriteWrapper(new GithubBadgeSkin.ZmAvatar()), text: user.name });
0
+ if ( _pl != null ) _pl.parent.removeChild(_pl);
0
+ _pl = new ProjectList()
0
+ _pl.setHeader({image: SpriteWrapper(new GithubBadgeSkin.DefaultAvatar()), text: user.name });
0
user.repositories.forEach( function(repo:Object, index:uint, arr:Array):void {
0
_pl.addButton({image: SpriteWrapper(new GithubBadgeSkin.PublicProject()), text: repo.name });
0
- private function displayError():void {
0
- private function getUserObject(json:String = null):Object {
0
- // Cheesy loading of cheesy test data
0
- json ||= '{"user": {"name": "Andrei Bocan", "repositories": [{"name": "mephisto", "url": "http://github.com/zmack/mephisto", "description": "A mirror of the mephisto code-base", "homepage": "http://mephistoblog.com/"}, {"name": "badjo", "url": "http://github.com/zmack/badjo", "description": "Github flash badge ", "homepage": ""}], "blog": "http://spinach.andascarygoat.com", "login": "zmack", "email": "zmaxor@gmail.com", "location": "Bucharest, Romania"}}';
0
- return JSON.decode(json).user;
0
+ private function displayError():void {
0
+ _pl.addChild(SpriteWrapper(new GithubBadgeSkin.OctocatImage()));
0
private function requestData(user:String):void {
0
_gw.addEventListener(GatewayEvent.DATA_RECEIVED, dataLoaded);
0
@@ -67,7 +86,7 @@ package {
0
displayProjectList(JSON.decode(e.data).user);
0
-
addChild(SpriteWrapper(new GithubBadgeSkin.OctocatImage()));
Comments
No one has commented yet.