topical media & game development
#springgraph-example.mx
[swf]
flex
<?xml version="1.0"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:fc="http://www.adobe.com/2006/fc"
initialize="onLoad()">
<fc:SpringGraph id="sg" width="100%" height="100%"
backgroundColor="#869ca7" repulsionFactor="1">
<fc:itemRenderer>
<mx:Component>
<mx:Label fontSize="14" text="{data.id}" color="#ffffff"/>
</mx:Component>
</fc:itemRenderer>
</fc:SpringGraph>
<mx:Parallel id="newItemEffect">
<mx:SoundEffect source="@Embed(source='../assets/sound/bloop.mp3')"/>
<mx:Blur duration="200"
blurXFrom="10.0" blurXTo="0.0"
blurYFrom="10.0" blurYTo="0.0"/>
</mx:Parallel>
<mx:Script>
<![CDATA[
import com.adobe.flex.extras.controls.springgraph.Graph;
import com.adobe.flex.extras.controls.springgraph.Item;
import flash.utils.Timer;
import flash.events.TimerEvent;
private var graph: Graph = new Graph();
private var rootItem: Item;
private var timer: Timer = new Timer(300, 0);
private var itemCount: int = 0;
private function onLoad(): void {
addNode("R");
timer.addEventListener("timer", timerHandler);
timer.start();
sg.addItemEffect = newItemEffect;
}
public function timerHandler(event:TimerEvent):void {
addNode(new Number(++itemCount).toString(), "R");
if(itemCount == 30)
timer.stop();
}
private function addNode(id:String, linkedTo:String = null): void {
var item: Item = new Item(id);
graph.add(item);
if(linkedTo)
graph.link(graph.find(linkedTo), item);
sg.dataProvider = graph;
}
]]>
</mx:Script>
</mx:Application>
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.