This blog has moved
This blog is now located at http://code.152.org/.
You will be automatically redirected in 30 seconds, or you may click here.
For feed subscribers, please update your feed subscriptions to
http://code.152.org/atom.xml.
This is a collection of various things I've learned along the way. Mostly programming or tech. No one in interested in how much coffee you drink or how much you miss 80's cartoons.
var asyncToken:AsyncToken; var internalIResponder:IResponder; ... asyncToken = _httpService.send(); internalIResponder = new AsyncResponder(onHTTPServiceSuccess, onHTTPServiceFault, asyncToken); asyncToken.addResponder(internalIResponder);
Labels: addEventListener, as, as3, asyncresponder, asynctoken, httpService, iresponder
<mx: Application xmlns: mx="http: //www.adobe. com/2006/mxml" xmlns: view="com.oreilly.view.*" layout="absolute" applicationComplete="contactsService.send()" > <mx:HTTPService id="contactsService" resultFormat="e4x" url="contacts.xml" /> <mx:DataGrid id="contactsDataGrid" dataProvider="{contactsService.lastResult.contact}" selectedIndex="0" left="10" top="10" bottom="10" width="300"> <mx: columns> <mx: DataGridColumn headerText="First" dataField="firstName"/> <mx: DataGridColumn headerText="Last" dataField="lastName"/> </mx:columns> </mx:DataGrid> <view: ContactViewer contact="{contactsDataGrid. selectedItem}" x="318" y="10"> </view: ContactViewer> </mx: Application>
dataProvider="{XMLList(XML(contactsService.lastResult).contact)}"
Labels: cast, casting, class, datagrid, dataprovider, error, flex, ieventdispatcher, lastResult, learning, warning, xml
<mx:Component> <itemRenderers:ImageTile_bad /> </mx:Component>
<?xml version="1.0" encoding="utf-8"?> <mx:Image xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> <mx:Script> <![CDATA[ /** * This is an example of how not to use an item render in a TileList * */ private function init() : void { this.source = data; this.name = data.toString().split("/").pop().split(".").shift(); } ]]> </mx:Script> </mx:Image>
<mx:Component> <itemRenderers:ImageTile img="{data}"/> </mx:Component>
<mx:Image xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ /** * This is an example of how to use an itemRenderer in a TileList * Create a setter that will always update the when the TileList redraws * */ public function set img(value:String) : void { //make sure there is something to work with. avoid error# 1010 if(!value) { return; } this.source = value; this.name = value.toString().split("/").pop().split(".").shift(); } ]]> </mx:Script> </mx:Image>
Labels: creationComplete, data, dataprovider, duplicate, flex, init, itemrenderer, override, random, redraw, refresh, repeat, switch, tilelist
package { import flash.display.Sprite; import flash.events.Event; import obj.Level1; import obj.Level3; public class event_bubbling_as extends Sprite { private var _level1:Level1 public function event_bubbling_as() { _level1 = new Level1; _level1.addEventListener(Level3.EVENT, onEvent); addChild(_level1); } private function onEvent(event:Event) : void { trace('caught event from level 3'); } } }Level1.as
package obj { import flash.display.Sprite; public class Level1 extends Sprite { private var _level2:Level2; public function Level1() { trace("in level 1"); _level2 = new Level2; addChild(_level2); } } }Level2.as
package obj { import flash.display.Sprite; public class Level2 extends Sprite { private var _level3:Level3; public function Level2() { trace("in level 2"); _level3 = new Level3; addChild(_level3); } } }Level3.as
package obj { import flash.display.Sprite; import flash.events.Event; public class Level3 extends Sprite { public static const EVENT:String = "level3"; public function Level3(){ trace("in level 3"); //trigger event when the object is added to the stage addEventListener(Event.ADDED_TO_STAGE, launchEvent); } public function launchEvent(event:Event) : void { var newEvent:Event = new Event(EVENT, true, true); dispatchEvent(newEvent); } } }You can download the Flex Project Archive example here. This can be directly imported into Flex. Run it in debug mode to see how each level is triggered.
Labels: 3, actionscript, actionscript3, as, as3, bubbling, capture, display, displayobjectcontainer, event, eventbubbling, eventdispatcher, eventlistener, events, flash, listener, sprite, targeting
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" styleName="plain"> <mx:Script> <![CDATA[ import obj.Level3; import obj.Level1; private var _level1:Level1; private function init() : void { trace("in the base"); _level1 = new Level1; //add eventListener _level1.addEventListener(Level3.EVENT,onEvent); addChild(_level1); } private function onEvent(event:Event) : void { trace("picked up event from Level3 "); } ]]> </mx:Script> </mx:Application>
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" initialize="init()"> <mx:Script> <![CDATA[ private var _level2:Level2; private function init() : void { trace("in level 1"); _level2 = new Level2; addChild(_level2); } ]]> </mx:Script> </mx:Canvas>
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" initialize="init()"> <mx:Script> <![CDATA[ private var _level3:Level3; private function init() : void { trace("in level 2"); _level3 = new Level3; addChild(_level3); } ]]> </mx:Script> </mx:Canvas>
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" initialize="init()"> <mx:Script> <![CDATA[ public static const EVENT:String = "level3"; private function init(): void { trace("in level 3"); var event:Event = new Event(EVENT,true,true); dispatchEvent(event); } ]]> </mx:Script> </mx:Canvas>
Labels: bubbling, capture, display, displayobject, event, eventbubbling, events, flex, listener, mxml, object, targeting