public
Description: Github flash badge
Homepage: http://spinach.andascarygoat.com/tags/badjo
Clone URL: git://github.com/zmack/badjo.git
Cleanup, some changes, external interface
zmack (author)
Wed Apr 30 00:08:53 -0700 2008
commit  f6dcfc42b2cc64316f5b3db1d7218a76d66ff400
tree    89f064b0cfc3a173a82da2bf91e6e0cab19b41e1
parent  cdf458f1b7cd292eaeca3fb2b35519734e98355b
...
3
4
5
6
7
 
 
8
9
10
...
3
4
5
 
 
6
7
8
9
10
0
@@ -3,8 +3,8 @@ package skins {
0
     [Embed(source="GithubBadge/ProjectSprouts.png")]
0
     public static var ProjectSprouts:Class;
0
 
0
- [Embed(source="GithubBadge/zmack.png")]
0
- public static var ZmAvatar:Class;
0
+ [Embed(source="GithubBadge/octocat.jpg")]
0
+ public static var DefaultAvatar:Class;
0
 
0
     [Embed(source="GithubBadge/public.png")]
0
     public static var PublicProject:Class;
...
1
2
3
 
4
5
6
7
 
 
8
9
10
...
26
27
28
 
29
30
 
 
 
 
 
 
 
 
 
31
32
33
34
35
 
 
36
37
 
 
 
 
 
 
 
 
38
39
40
...
42
43
44
45
 
 
 
 
46
47
48
49
50
51
52
 
53
54
55
56
57
58
 
 
59
60
61
 
62
63
64
...
67
68
69
70
 
71
72
73
...
1
2
3
4
5
6
7
8
9
10
11
12
13
...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
 
 
46
47
48
 
49
50
51
52
53
54
55
56
57
58
59
...
61
62
63
 
64
65
66
67
68
69
70
 
 
 
71
72
73
74
 
 
 
 
75
76
77
78
79
80
81
82
83
...
86
87
88
 
89
90
91
92
0
@@ -1,10 +1,13 @@
0
 package {
0
   import flash.display.Sprite;
0
   import flash.display.DisplayObject;
0
+ import flash.display.LoaderInfo;
0
   import skins.GithubBadgeSkin;
0
   import dataexchange.*;
0
   import com.adobe.serialization.json.JSON;
0
 
0
+ import flash.external.ExternalInterface;
0
+
0
   /*
0
   Data looks pretty much like this:
0
 
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
 
0
     public function GithubBadge() {
0
+ var user:String;
0
+ addExternalInterface();
0
+
0
+ try {
0
+ user = getParams().gitUser;
0
+ } catch (e:Error) {
0
+ user = 'evilchelu';
0
+ }
0
+
0
       _gw = new Gateway();
0
       
0
- _pl = new ProjectList();
0
- addChild(_pl);
0
- _pl.y = 20;
0
+ this.requestData(user);
0
+ }
0
 
0
- this.requestData('evilchelu');
0
+ private function addExternalInterface():void {
0
+ if ( ExternalInterface.available ) {
0
+ ExternalInterface.addCallback("requestData",requestData);
0
+ }
0
+ }
0
+
0
+ private function getParams():Object {
0
+ return LoaderInfo(this.loaderInfo).parameters;
0
     }
0
 
0
     private function onDataLoaded(e:GatewayEvent):void {
0
@@ -42,23 +61,23 @@ package {
0
     }
0
 
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
+
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
       });
0
- }
0
-
0
- private function displayError():void {
0
 
0
+ addChild(_pl);
0
     }
0
 
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
     }
0
 
0
     private function requestData(user:String):void {
0
+ _user = user;
0
       _gw.getUserInfo(user);
0
       _gw.addEventListener(GatewayEvent.DATA_RECEIVED, dataLoaded);
0
     }
0
@@ -67,7 +86,7 @@ package {
0
       if ( e.succeeded ) {
0
         displayProjectList(JSON.decode(e.data).user);
0
       } else {
0
- addChild(SpriteWrapper(new GithubBadgeSkin.OctocatImage()));
0
+ displayError();
0
       }
0
       trace(e.data);
0
     }

Comments

    No one has commented yet.