Skip to main content

Posts

AS3: Minimum code required to load XML at run-time

Minimum code required to load XML at run-time is given below: SOURCE CODE var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener (Event.COMPLETE, onEventComplete); urlLoader.load (new URLRequest('Database.xml')); function onEventComplete (e:Event):void { var Xml:XML = new XML(URLLoader(e.target).data); trace (Xml); }

AS3: How to load XML in swf at run-time

We can load xml file into swf at run-time by using following class. SOURCE CODE package { import flash.display.Sprite; import flash.events.*; import flash.net.*; /** * @file CLoader.as * @author Abhishek Kumar */ public class CLoader extends Sprite { private var oDispatcher:CDispatcher; public function CLoader() { oDispatcher = CDispatcher.getInstance(); } public function retrieve(iXml:String):void { var loader:URLLoader = new URLLoader(); configureListeners(loader); var request:URLRequest = new URLRequest(iXml); try { loader.load(request); } catch (error:Error) { trace("Loading failed!"); } } private function configureListeners(dispatcher:IEventDispatcher):void { dispatcher.addEventListener(Event.COMPLETE, completeHandler); dispatcher.addEventListener(Event.OPEN, openHandler); dispatcher.add...

AS3: How to create custom event dispatcher class

We can create custom event dispatcher class as given below: SOURCE CODE package { import flash.events.EventDispatcher; import flash.events.Event; /** * @file CDispatcher.as * @author Abhishek Kumar */ public class CDispatcher extends EventDispatcher { public static var ACTION:String = "action"; public static var ERROR:String = "error"; private static var instance:CDispatcher = new CDispatcher(); public function CDispatcher() { if (instance) throw new Error("Error: Instantiation failed!"); } public static function getInstance():CDispatcher { return instance; } public function dispatch(e:String, o:Object=null):void { dispatchEvent(new CEvent(e, o)); } } } USAGE import CDispatcher; import CEvent; var oDispatcher:CDispatcher = CDispatcher.getInstance(); oDispatcher.addEventListener (CDispatcher.ACTION, actionHandler); oDispatcher.addEventListener (CDi...

AS3: How to create custom event class with extra parameters

We can create a custom event class with extra properties to pass data with it. The source code is given below. SOURCE CODE package { import flash.events.Event; /** * @file CEvent.as * @author Abhishek Kumar */ public class CEvent extends Event { public static const CUSTOM_EVENT: String = "custom_event"; public var data:Object; public function CEvent(type:String, data:Object, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); this.data = data; } override public function clone():Event { return new CEvent(type, data, bubbles, cancelable); } } } -- Note: Here we can dispatch event as show below: dispatchEvent(new CEvent(CEvent.CUSTOM_EVENT, objekt));

Einstein’s Riddle

It's a riddle created by Albert Einstein . But the beauty of this riddle is that it doesn't involve physics. You have to just apply your logic. But he had declared that "98% of the world population would not be able to solve it" So do you have guts to try it? The Riddle: In a town, there are five houses, each painted with a different color. In every house lives a person of different nationality. Each homeowner drink a different beverage, smokes a different brand of cigar, and owns a different type of pet. The Question: Who owns the fishes? Hints: The Brit lives in a red house. The Swede keeps dogs as pets. The Dane drinks tea. The Green house is next to, and on the left of the White house. The owner of the Green house drinks coffee. The person who smokes Pall Mall rears birds. The owner of the Yellow house smokes Dunhill. The man living in the center house drinks milk. The Norwegian lives in the first house. The man who smokes Blends live...