Posted by Riccardo on February 7, 2011 under Actionscript 3, Flash, Snippets
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| package com.rblab.framework.net { import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IOErrorEvent; import flash.net.URLLoader; import flash.net.URLRequest; /** * Dispatched when the instance has successfully unshortened an url. * @eventType flash.events.COMPLETE */ [Event(name="complete", type="flash.events.Event")] /** * Dispatched when the instance has encountered an error while trying to unshorten your url. * @eventType flash.events.IOErrorEvent.IO_ERROR */ [Event(name="ioError", type="flash.events.IOErrorEvent")] /** * URL Unshortener Class using http://untiny.me/ public service * For a list of supported services see <a href="http://untiny.me/api/1.0/services/" target="_blank">http://untiny.me/api/1.0/services/</a> * @author Sandro Ducceschi [swfjunkie.com, Switzerland] */ public class URLUnshortener extends EventDispatcher { //-------------------------------------------------------------------------- // // Class variables // //-------------------------------------------------------------------------- private static const UNTINY_ME_URL:String = "http://untiny.me/api/1.0/extract?format=text&url="; //-------------------------------------------------------------------------- // // Initialization // //-------------------------------------------------------------------------- /** * Creates a new URLShortener Instance */ public function URLUnshortener() { init(); } /** * @private * Initializes the instance. */ private function init():void { urlLoader = new URLLoader(); urlRequest = new URLRequest(); urlLoader.addEventListener(Event.COMPLETE,handleComplete); urlLoader.addEventListener(IOErrorEvent.IO_ERROR,handleError); } //-------------------------------------------------------------------------- // // Variables // //-------------------------------------------------------------------------- private var urlLoader:URLLoader; private var urlRequest:URLRequest; //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** @private */ private var _url:String; /** * The Unshortened URL */ public function get url():String { return _url; } //-------------------------------------------------------------------------- // // API // //-------------------------------------------------------------------------- /** * Unshortens the given URL * @param url Short URL that should be unshortened */ public function unshorten(url:String):void { _url = null; urlRequest.url = UNTINY_ME_URL + url; urlLoader.load(urlRequest); } /** * Completely destroys the instance and frees all objects for the garbage * collector by setting their references to null. */ public function destroy():void { _url = null; urlLoader = null; urlRequest = null; urlLoader.removeEventListener(Event.COMPLETE,handleComplete); urlLoader.removeEventListener(IOErrorEvent.IO_ERROR,handleError); } //-------------------------------------------------------------------------- // // Eventhandling // //-------------------------------------------------------------------------- /** @private */ private function handleComplete(event:Event):void { if (String(urlLoader.data).indexOf("error") != -1) dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR, false, false, urlLoader.data.toString())); else { _url = urlLoader.data; dispatchEvent(new Event(Event.COMPLETE)); } } /** @private */ private function handleError(event:IOErrorEvent):void { dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"Unshortening failed")); } } } |
Tags: Actionscript 3, as3, as3 flash, Flash, snippet, Snippets
Posted by Riccardo on February 7, 2011 under Actionscript 3, Flash, Snippets
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| package com.rblab.framework.net { import flash.events.Event; import flash.events.EventDispatcher; import flash.events.IOErrorEvent; import flash.net.URLLoader; import flash.net.URLRequest; /** * Dispatched when the instance has successfully shortened an url. * @eventType flash.events.COMPLETE */ [Event(name="complete", type="flash.events.Event")] /** * Dispatched when the instance has encountered an error while trying to encode your url. * @eventType flash.events.IOErrorEvent.IO_ERROR */ [Event(name="ioError", type="flash.events.IOErrorEvent")] /** * URL Shortener Class using <a href="http://is.gd/" target="_blank">http://is.gd/</a> public service * @author Sandro Ducceschi [swfjunkie.com, Switzerland] */ public class URLShortener extends EventDispatcher { //-------------------------------------------------------------------------- // // Class variables // //-------------------------------------------------------------------------- private static const IS_GD_URL:String = "http://is.gd/api.php?longurl="; //-------------------------------------------------------------------------- // // Initialization // //-------------------------------------------------------------------------- /** * Creates a new URLShortener Instance */ public function URLShortener() { init(); } /** * @private * Initializes the instance. */ private function init():void { urlLoader = new URLLoader(); urlRequest = new URLRequest(); urlLoader.addEventListener(Event.COMPLETE,handleComplete); urlLoader.addEventListener(IOErrorEvent.IO_ERROR,handleError); } //-------------------------------------------------------------------------- // // Variables // //-------------------------------------------------------------------------- private var urlLoader:URLLoader; private var urlRequest:URLRequest; //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** @private */ private var _url:String; /** * The Shortened URL */ public function get url():String { return _url; } //-------------------------------------------------------------------------- // // API // //-------------------------------------------------------------------------- /** * Shortens the given URL * @param url Long URL that should be shortened */ public function shorten(url:String):void { _url = null; urlRequest.url = IS_GD_URL + url; urlLoader.load(urlRequest); } /** * Completely destroys the instance and frees all objects for the garbage * collector by setting their references to null. */ public function destroy():void { _url = null; urlLoader = null; urlRequest = null; urlLoader.removeEventListener(Event.COMPLETE,handleComplete); urlLoader.removeEventListener(IOErrorEvent.IO_ERROR,handleError); } //-------------------------------------------------------------------------- // // Eventhandling // //-------------------------------------------------------------------------- /** @private */ private function handleComplete(event:Event):void { _url = urlLoader.data; dispatchEvent(new Event(Event.COMPLETE)); } /** @private */ private function handleError(event:IOErrorEvent):void { dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR,false,false,"Shortening failed")); } } } |
Tags: Actionscript 3, as3, as3 flash, snippet, Snippets
Posted by Riccardo on February 7, 2011 under Actionscript 3, Flash, Papervision 3D, Snippets
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| package com.rblab.framework.papervision { import org.papervision3d.cameras.Camera3D; import org.papervision3d.cameras.CameraType; import org.papervision3d.cameras.DebugCamera3D; import org.papervision3d.cameras.SpringCamera3D; import org.papervision3d.core.proto.CameraObject3D; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import flash.display.Sprite; /** * @author Riccardo Bartoli */ public class PapervisionView extends Sprite { //-------------------------------------------------------------------------- // // Private properties // //-------------------------------------------------------------------------- private var _viewportWidth : Number; private var _viewportHeight : Number; private var _scaleToStage : Boolean; private var _interactive : Boolean; private var _cameraType : String; //-------------------------------------------------------------------------- // // Protected properties // //-------------------------------------------------------------------------- protected var scene : Scene3D; protected var viewport : Viewport3D; protected var renderer : BasicRenderEngine; protected var camera : CameraObject3D; //-------------------------------------------------------------------------- // // Constructor // //-------------------------------------------------------------------------- public function PapervisionView(viewportWidth : Number, viewportHeight : Number, scaleToStage : Boolean, interactive : Boolean, cameraType : String) { this._viewportWidth = viewportWidth; this._viewportHeight = viewportHeight; this._scaleToStage = scaleToStage; this._interactive = interactive; this._cameraType = cameraType; init(); } //-------------------------------------------------------------------------- // // Private methods // //-------------------------------------------------------------------------- private function init() : void { setupScene(); setupCamera(_cameraType); setupPapervision(); } private function setupScene() : void { scene = new Scene3D(); viewport = new Viewport3D(_viewportWidth, _viewportHeight, _scaleToStage, _interactive); addChild(viewport); renderer = new BasicRenderEngine(); } private function setupCamera(cameraType : String) : void { switch(cameraType) { case CameraType.DEBUG: camera = new DebugCamera3D(viewport); break; case CameraType.TARGET: camera = new Camera3D(60); camera.target = DisplayObject3D.ZERO; break; case CameraType.SPRING: camera = new SpringCamera3D(); camera.target = DisplayObject3D.ZERO; break; case CameraType.FREE: default: camera = new Camera3D(60); break; } camera.focus = 100; camera.z = -1000; camera.zoom = 10; } private function setupPapervision() : void { viewport.buttonMode = _interactive; viewport.interactive = _interactive; } //-------------------------------------------------------------------------- // // Protected methods // //-------------------------------------------------------------------------- protected function render() : void { renderer.renderScene(scene, camera, viewport); } } } |
Tags: Actionscript 3, as3, as3 flash, papervision, snippet, Snippets
« Newer Entries — Older Entries »