HTTPService and ArrayCollection in Flash CS4


Recently I had a need to use the HTTPService & ArrayCollection Flex classes from inside Flash CS4. In order to do this you need to point to the Flex classes in your Flash preferences as outlined in this post. Code after the jump.

  Twitter Search (380.5 KiB, 51 hits)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
package {
 
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import fl.controls.UIScrollBar;
 
	//FLEX classes
	import mx.rpc.http.HTTPService;
	import mx.rpc.events.ResultEvent;
	import mx.collections.ArrayCollection;
 
	public class TwitterSearch extends MovieClip {
 
		private var _twitterService:HTTPService = new HTTPService();
		private var _arr:ArrayCollection;
		private var _twitterMsgs_txt:TextField = new TextField();
 
		public function TwitterSearch ():void{
			addEventListener (Event.ADDED_TO_STAGE, init, false, 0, true);
		}
		private function init (e:Event):void {
			var searchTerm:String = 'as3';
			//Load Twitter Feed
			_twitterService.url = 'http://search.twitter.com/search.atom?q=' + searchTerm;
			_twitterService.send();
			_twitterService.addEventListener(ResultEvent.RESULT, onTwitterResult, false, 0, true);
		}
 
		private function onTwitterResult(e:ResultEvent): void {
			_arr = e.result.feed.entry as ArrayCollection;
 
			var tweets:String;
			for (var i:int = 0;i < _arr.length;i++) {
				tweets += _arr[i].title + 'n';
			}
 
			var textFormat:TextFormat = new TextFormat();
			textFormat.size = 12;
			textFormat.color = 0xFFFFFF;
 
			_twitterMsgs_txt.defaultTextFormat = textFormat;
			_twitterMsgs_txt.border = true;
			_twitterMsgs_txt.borderColor = 0xFFFFFF;
			_twitterMsgs_txt.background = true;
			_twitterMsgs_txt.backgroundColor = 0x333333;
			_twitterMsgs_txt.width = 860; 
			_twitterMsgs_txt.height = 440; 
			_twitterMsgs_txt.x = 50;
			_twitterMsgs_txt.y = 50;
			_twitterMsgs_txt.text = tweets;
 
			addChild (_twitterMsgs_txt);
		}
	}
}
Spread the Good Word:
  • Digg
  • del.icio.us
  • Facebook
  • NewsVine
  • StumbleUpon

, , ,

  1. No comments yet.
(will not be published)

Switch to our mobile site