在Flex中使用JSON新手入门: 读取豆瓣API

Categories: Flex; Tagged with: ; @ December 13th, 2012 17:59

豆瓣提供了丰富的API, 在Flex中可使用WebService快速调用。

读取指定用户收藏过的图书:

image

 

在Flex中使用JSON

FlashPlayer 11开始原生支持JSON:

Native JSON (JavaScript Object Notation) Support — Allows ActionScript developers to take advantage of high performance native parsing and generation of JSON-formatted data.

http://helpx.adobe.com/x-productkb/multi/release-notes-flash-player-11.html

在Flex SDK 4.6中已有顶级类: JSON。

如果使用旧的SDK, 则可以as3corelib:

An ActionScript 3 Library that contains a number of classes and utilities for working with ActionScript? 3. These include classes for MD5 and SHA 1 hashing, Image encoders, and JSON serialization as well as general String, Number and Date APIs.

不过看起来已经有两年多没有更新了。 swc下载地址:  https://github.com/mikechambers/as3corelib/downloads

SDK4.6与As3CoreLib中JSON Class的method name略有不同。

代码:

			private function onJSONLoad(event:ResultEvent):void
			{
				var rawData:String = String(event.result);
				var rawResult:Object = JSON.parse(rawData);
				var books:Array = (rawResult.collections as Array);
				
				var dp:ArrayCollection = new ArrayCollection(books);
				dataGridBooks.dataProvider = dp;
			}

在GitHub上查看完整代码:https://github.com/DavidGuoliang/DoubanAnalytics/blob/master/src/DouBanJson.mxml

Using XML filter in ActionScript – Flex中过滤XML

Categories: Flex; Tagged with: ; @ March 1st, 2012 22:44

我一直不喜欢在AS中频繁的操作XML, 但没办法, 最近所有的data都是来自于XML, 没有任何ValueObject, 清一色的XML.

把把都得翻书找手册 🙁  弱到爆

 

image

Trace到的结果:

image

ActionScript: conversion to Boolean

Categories: Flex; Tagged with: ; @ February 27th, 2012 19:46

The following table summarizes the results of casting to the Boolean data type from other data types:

Data type or value Result of conversion to Boolean
String false if the value is null or the empty string ( “” ); true otherwise.
null false
Number, int or uint false if the value is NaN or 0; true otherwise.
Object false if the instance is null ; true otherwise.

ref:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f87.html

Note: when you convert a string to boolean, remeber to trim the string first.

and this is a capture from <<Essential ActionScript 3.0>>:

image



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.