Home

Archive for the Category » Code Examples «

HTML5 Tests

Thursday, May 23rd, 2013 | Author:

Testing some ideas using different tools to make HTML5 graphics and animations
createjs game1 icon #1 – quick incomplete game made with CreateJS and Haxe First impressions seems to do the cross browser thing well and and the Haxe JS externs for CreateJS save time too.



UPDATE: #2 Here is a Haxe/FlashDevelop project of the CJS Getting started tutorial and video – uses CreateJS externs (haxelib install createjs)


 Chrome Web Audio + Three.js icon UPDATE: #3: Trying the newly released Haxe3 Javascript export using it to create a Chrome Web Audio sound visualisation using Three.js only tested in Chrome. 3D based on one of the examples sound file (9mb so it takes a while to load) Plurabelle_-_05_-_Light_Livid.mp3 found at freemusicarchive.org


UPDATE: #4 Here another Three.js WebGL test doing simple line drawing – a few glitches but can definitely see a bicycle outline there. Could animate the drawing it out like I did in this example – some sort of guess the shape game maybe.


 CSS 3D icon UPDATE: #5 Added some new HTML5 code examples to CodePen first a fluid 3D interactive image viewer drag over it to twist the image in 3D space


particles iconSecond some Pink Particles as an entry to the Codepen Rodeo


Chrome Audio iconThird I used the Chrome Web Audio API to make a simple audio visualiser to use as a template. Best viewed in the Google Chrome Browser.

Category: Code Examples, Haxe, HTML5, Javascript | Leave a Comment

Haxe NME PureData Android Example

Monday, May 07th, 2012 | Author:

Found no examples online of using Haxe + PureData together so far so I wrote a proof of concept for Android using PDCore from libpd pd-for-android to generate some noise on a droid. Open the FlashDevelop project and press Ctrl-Enter with your Android phone connected then drag the red dot around on screen.

You can download the Haxe and Java source code and FlashDevelop project from here HaxePureDataProofOfConcept.zip

It uses Haxe NME 3 and Haxe 2.09 and compiles on Win7 64bit and the apk runs on armv6 CM7 Android 2.3 so hope it works on other systems. May not be the best way to do it (could be made a NMEX for example) and probably not bug free but it makes a start and shows them working together. Will write up a more detailed description some time but the source code is there.

Some of the Haxe/Android/PureData links I have found useful are below:
Haxe NME
Getting Started
Haxe Google Groups
Creating an NME Extension
Android NME+Java
@ gigglingcorpse
– lots of useful blog posts
PureData Example
Android Monkey testing – $ adb shell monkey -p your.package.name -v 500
FindBugs & PMD Java tools for Eclipse
color for logcat
FlashDevelop

Category: Code Examples, Flash, Haxe, Mobile | Comments off

Basic AS3 VAST OVA Video Player Example

Sunday, March 11th, 2012 | Author:

Just a short single class that does pre-roll VAST video ads (Google VAST docs here). It uses the longtailvideo OVA for AS3 with more details at OVA SWC ova-as3-1.0.1.swc and the video player from here apdevblog with pre-roll and main video clips from the Test Ads at the old openx-iab-vast site. The config object is declared in the Actionscript as ‘rawConfigLocal’ for simplicity. There is a lot more that can be implemented but this is a very short and incomplete demo that might help as a starting point to have a simple example under 100 lines. The VAST XML is below too.
more…

Category: Code Examples, Flash | 4 Comments

Drawing fonts using Javascript Canvas and easelJS

Tuesday, May 31st, 2011 | Author:

Drawing fonts using Javascript Canvas and easelJS
Spent a couple hours playing with easelJS and tried emulating something from Flash AS1 era which still needs some work but uploaded here . It uses a single Shape on the Stage with a single Graphic instance inside it which gets drawing commands in the Ticker timer producing a “Flash” type animation using only Javascript. Using JS rather than SWF means testing how different browsers display it. FF4 and Opera 11.50 labs work, FF3.6 partly works but stops after the first animation (there should be about 10 different Webdings font characters displayed one after another).

Category: Code Examples, Javascript | Comments off

Updated Flash AS3 RobotLegs YouTube code

Friday, August 20th, 2010 | Author:

RobotLegs YouTube Example2 Added a GUI and a search facility to the previous example. The demo movie is here and the source code is here . Still needs some work to improve the GUI and performance which will be added some time.

Category: Code Examples, Flash, RobotLegs, YouTube API | Comments off

Flash AS3 RobotLegs YouTube example

Monday, August 09th, 2010 | Author:

RobotLegs YouTube Example Was asked about an updated Flash YouTube example as the previous ones were quite old and Flex based. So here is a work in progress which I will update later. Still need to add a GUI and a search facility but this is the basic version for now. It uses MVCS in RobotLegs and MinimalComps to interface with YouTube. The demo movie is here and the source code is here and the demo search was Ronettes…
Some ideas used in the code were taken from three excellent articles here and here and here

Category: Code Examples, Flash, RobotLegs, YouTube API | 2 Comments

AS3 Signals Bubbling note

Sunday, March 07th, 2010 | Author:

Working with this now and just a note that it looks like a way to bubble Signals from a nested display class is as follows:

public var deluxeSignal:DeluxeSignal = new DeluxeSignal(this);

deluxeSignal.dispatch(new GenericEvent(true));

and the listening class further up the display list implements IBubbleEventHandler and requires the following method:

public function onEventBubbled(e:IEvent):void {
trace(e +"-"+ e.target +"-"+ e.currentTarget +"-"+ e.signal);
}

- – -
Added a quick example below with source code using the current signals release unedited
here

PS there is an excellent Signals video tutorial here

- – -
Update: Added a new version of the simple example that works with the latest Signals release (0.7). The onEventBubbled method now has a boolean return value to determine whether to continue bubbling or stop.
The new example code can be downloaded here

Update: Added a new simple example using Signals 0.8 bubbling + custom event based on one of the test cases which helps with strong typing and can be downloaded here
- – -

Some ideas on passing parameters:
var deluxeSignal:DeluxeSignal = new DeluxeSignal(this);
deluxeSignal.dispatch(new GenericEvent(true));
Here you are passing “this”, ie the sending instance, as the GenericEvent event target so that it is available as the event.target within onEventBubbled(event:IEvent).

Alternately pass in a Value Object (VO) instead of “this” to pass more precise and data typed parameters (you would need to give it a “parent” property) or another option is to extend GenericEvent and give it some custom properties which can be read within onEventBubbled.

Category: Code Examples, Flash | 18 Comments

Quick test of FCSS

Sunday, February 14th, 2010 | Author:

fcss test Spent an hour testing the cool Flash AS3 FCSS library. Seems fine to set any public property so it can trigger tweens, image loads, filters etc as in this example
There is a good FCSS video tutorial here

Trees image from here released under CC license


Code below all in one file for now as it was just a quick test. Aside from FCSS it also uses three other AS3 libraries – Tweener and MinimalComps and BumpSlide

You can view the swf here

ActionScript
< view plain text >
  1. /**
  2. * v0.1 code by dehash.com 2010
  3. * Quick Test of FCSS
  4. * Released as open source under the BSD License
  5. * http://www.opensource.org/licenses/bsd-license.php
  6. */
  7. package {
  8.  
  9.     // http://code.google.com/p/minimalcomps/
  10.     import com.bit101.components.*;
  11.  
  12.     // http://github.com/theflashbum/fcss
  13.     import com.flashartofwar.fcss.applicators.StyleApplicator;
  14.     import com.flashartofwar.fcss.managers.SingletonManager;
  15.     import com.flashartofwar.fcss.styles.IStyle;
  16.     import com.flashartofwar.fcss.stylesheets.*;
  17.  
  18.     import flash.display.Sprite;
  19.     import flash.events.Event;
  20.     import flash.events.MouseEvent;
  21.  
  22.     // trees image from http://www.flickr.com/photos/cybot586/4356730349/
  23.  
  24.     public class Main extends Sprite
  25.     {
  26.  
  27.         private var css:XML = <css><![CDATA[
  28.         #boxStyle {
  29.             x: 50;
  30.             y: 10;
  31.             alpha: 0.95;
  32.             width: 300;
  33.             height: 250;
  34.             color: 0x1C2331;
  35.             tweenYto: 333;
  36.             dropShadowDistance: 20;
  37.             loadImage: 4356730349_2cfcbdff4d.jpg;
  38.         }
  39.         ]]>
  40.         </css>;
  41.  
  42.         private var styleSheetCollection:IStyleSheetCollection =
  43. SingletonManager.getClassReference(StyleSheetCollection) as IStyleSheetCollection;
  44.  
  45.         private var txt:Text;
  46.  
  47.         private var box:BoxExtended;
  48.  
  49.         public function Main():void
  50.         {
  51.             if (stage) init();
  52.             else addEventListener(Event.ADDED_TO_STAGE, init);
  53.         }
  54.  
  55.         private function init(e:Event = null):void
  56.         {
  57.             removeEventListener(Event.ADDED_TO_STAGE, init);
  58.  
  59.             // entry point
  60.             addControls();
  61.             addBox();
  62.         }
  63.  
  64.         private function addControls():void {
  65.  
  66.             var window:Window = new Window(this, 400, 50, "Box CSS Window");
  67.             window.width = 320;
  68.             window.height = 460;
  69.  
  70.             var vBox:VBox = new VBox(window.content);
  71.  
  72.             txt = new Text(vBox, 10, 20);
  73.             txt.text = css.toString();
  74.             txt.width = 300;
  75.             txt.height = 400;
  76.  
  77.             new PushButton(vBox, 180 , 0, "Apply CSS to Box", parseButtonHandler);
  78.  
  79.         }
  80.  
  81.         private function parseButtonHandler(e:MouseEvent):void {
  82.  
  83.             var styleSheet:IStyleSheet = new FStyleSheet( );
  84.             styleSheet.parseCSS(txt.text.toString());
  85.  
  86.             styleSheetCollection.removeStyleSheet("boxStyleSheet");
  87.             styleSheetCollection.addStyleSheet(styleSheet, "boxStyleSheet");
  88.  
  89.             var boxStyle:IStyle = styleSheetCollection.getStyle("#boxStyle");
  90.  
  91.             var styleApplicator:StyleApplicator = new StyleApplicator();
  92.             styleApplicator.applyStyle(box,boxStyle);
  93.         }
  94.  
  95.         private function addBox():void {
  96.             box = new BoxExtended();
  97.             addChild(box);
  98.         }
  99.  
  100.     }
  101. }
  102.  
  103. // http://code.google.com/p/tweener/
  104. import caurina.transitions.Tweener;
  105. import flash.filters.DropShadowFilter;
  106. // http://code.google.com/p/bumpslide/
  107. import com.bumpslide.events.UIEvent;
  108. import com.bumpslide.ui.Box;
  109. import com.bumpslide.ui.Image;
  110.  
  111. class BoxExtended extends Box {
  112.  
  113.     private var image:Image = new Image(null, Image.SCALE_CROP, -1, -1, imageLoaded);
  114.     private var _tweenYto:Number;
  115.     private var _loadImage:String;
  116.     private var _dropShadowDistance:Number;
  117.  
  118.     public function BoxExtended() {
  119.         super(0xccccff,100,100,20,20);
  120.     }
  121.  
  122.     public function set tweenYto(value:Number):void {
  123.         _tweenYto = value;
  124.         Tweener.addTween(this, { y:_tweenYto, time:2.5, delay:0.5, transition:"easeInOutExpo" } );
  125.     }
  126.  
  127.     public function set loadImage(value:String):void {
  128.         _loadImage = "/demoimages/"+ value.split("/").pop();
  129.         if (_loadImage == "null") {
  130.             tileBitmap = null;
  131.         }else {
  132.             image.url = _loadImage;
  133.         }
  134.     }
  135.  
  136.     public function set dropShadowDistance(value:Number):void {
  137.         _dropShadowDistance = value;
  138.         filters = [new DropShadowFilter(_dropShadowDistance)];
  139.     }
  140.  
  141.     private function imageLoaded(e:UIEvent):void {
  142.         tileBitmap = image.imageBitmap.bitmapData;
  143.     }
  144.  
  145. }

Category: Code Examples, Flash | 3 Comments

Flash 10 3D example

Wednesday, December 23rd, 2009 | Author:

fp10 3d example3D Flash Player 10 example and code using PaperSprite and the new built in 3D instead of PaperVision. The output is similar to similar to the InteractivePlanesBoard example and some of it is loosely based on this example code too.
view swf here


ActionScript
< view plain text >
  1. /**
  2. * v0.1 code by dehash.com 2009
  3. * Flash Player 10 swf using PaperSprite similar to InteractivePlanesBoard
  4. * http://www.dehash.com/?page_id=219 only using FP10 3D rather than PV3D
  5. * code loosely based on example at :
  6. * http://blog.soulwire.co.uk/code/open-source/two-sided-planes-in-flash-player-10
  7. * Released as open source under the BSD License
  8. * http://www.opensource.org/licenses/bsd-license.php
  9. */
  10.  
  11. package  {
  12.     import flash.events.Event;
  13.     import flash.events.MouseEvent;
  14.     import flash.display.Sprite;
  15.    
  16.     //http://blog.soulwire.co.uk/code/open-source/two-sided-planes-in-flash-player-10
  17.     import soulwire.display.PaperSprite;
  18.    
  19.     // http://code.google.com/p/tweener/
  20.     import caurina.transitions.Tweener;
  21.  
  22.     [SWF(width="800", height="600", backgroundColor="0xFFFFFF")]
  23.  
  24.     public class InteractivePlanesBoard10Multi2CleanedUp extends Sprite {
  25.  
  26.         private const NUM_OBJECTS:uint = 4;
  27.  
  28.         [Embed(source='add.png')]
  29.         private var pic:Class;
  30.  
  31.         private var size:uint = 100;
  32.         private var cnt:uint = 0;
  33.         private var holder:PaperSprite;
  34.  
  35.         public function InteractivePlanesBoard10Multi2CleanedUp() {
  36.             holder = new PaperSprite();
  37.             addChild(holder);
  38.             holder.x = stage.stageWidth / 2;
  39.             holder.y = stage.stageHeight / 2;
  40.  
  41.             var xOffset:Number = (NUM_OBJECTS * size) / 2;
  42.             var yOffset:Number = (NUM_OBJECTS * size) / 2;
  43.  
  44.             for (var i:int = 0; i < NUM_OBJECTS; i++) {
  45.                 for (var j:int = 0; j < NUM_OBJECTS; j++) {
  46.  
  47.                     var paperSprite:PaperSprite = new PaperSprite();
  48.                     paperSprite = new PaperSprite();
  49.                     paperSprite.x = -xOffset + (i * size * 1.2);
  50.                     paperSprite.y = -yOffset + (j * size * 1.2);
  51.  
  52.                     if(cnt%5==0){
  53.                         paperSprite.front = createPicSprite();
  54.                     }else {
  55.                         paperSprite.front = createSprite();
  56.                     }
  57.  
  58.                     paperSprite.back = createSprite()
  59.                     paperSprite.rotationY = 0;
  60.                     holder.addChild(paperSprite );
  61.  
  62.                     paperSprite.addEventListener(MouseEvent.MOUSE_OVER, planePressedHandler, false, 0, true);
  63.  
  64.                     cnt++;
  65.                 }
  66.             }
  67.  
  68.             addEventListener ( Event.ENTER_FRAME, spin );
  69.         }
  70.  
  71.         private function createSprite ():Sprite {
  72.             var sp:Sprite = new Sprite();
  73.             sp.graphics.beginFill ( Math.random() * 0xffffff );
  74.             sp.graphics.drawRect ( -size / 2, -size / 2, size, size);
  75.             sp.graphics.endFill ();
  76.             return sp;
  77.         }
  78.  
  79.         public function createPicSprite():Sprite {
  80.             var sp:Sprite = new Sprite();
  81.             var b:*= new pic();
  82.             b.width = b.height = size;
  83.             sp.addChild(b);
  84.             return sp;
  85.         }
  86.  
  87.         private function spin ( event:Event ):void {
  88.             var mX:Number = ((mouseX / stage.stageWidth) - 0.5) * 360;
  89.             var mY:Number = ((mouseY / stage.stageHeight) - 0.5) * 360;
  90.             holder.rotationY += (mX - holder.rotationY) / 140;
  91.             holder.rotationX += (mY - holder.rotationX) / 140;
  92.         }
  93.  
  94.         public function planePressedHandler(e:MouseEvent):void {
  95.             if (!Tweener.isTweening(e.currentTarget)) {
  96.                 Tweener.addTween(e.currentTarget, { time:2, delay:0, transition:'easeinoutback', rotationY: e.currentTarget.rotationY + 180 } );
  97.             }
  98.         }
  99.  
  100.     }
  101. }

Category: Code Examples, Flash | Comments off

Quick Image Viewer

Thursday, November 26th, 2009 | Author:

Image ViewerMade a quick image displayer with zoom and pan in just a few lines of code using BumpSlide and MinimalComps which can be viewed here. The main source code is below and the image is The Starry Night by Van Gogh from here


ActionScript
< view plain text >
  1. /**
  2. * v0.1 code by dehash.com 2009
  3. * based on example code at :
  4. * http://bumpslide.googlecode.com/svn/trunk/as3/examples/zoom/ZoomDemo_01.as
  5. * Released as open source under the BSD License
  6. * http://www.opensource.org/licenses/bsd-license.php
  7. */
  8.  
  9. package {
  10.  
  11. import com.bit101.components.HBox;
  12. import com.bit101.components.HSlider;
  13. import com.bit101.components.Label;
  14. import com.bit101.components.PushButton;
  15.  
  16. import com.bumpslide.ui.Applet;
  17. import com.bumpslide.ui.ZoomPanel;
  18. import net.stevensacks.utils.Web;
  19.  
  20. import flash.display.Bitmap;
  21. import flash.display.Loader;
  22. import flash.events.Event;
  23. import flash.events.MouseEvent;
  24. import flash.net.URLRequest;
  25.  
  26. public class ImageDisplayer extends Applet {
  27.  
  28. static private const CONTENT_URL:String = "starrynight1280.jpg";
  29. private var zoomPanel:ZoomPanel;
  30. private var image:Loader;
  31. private var myZoomSlider:HSlider;
  32. private var controls:HBox;
  33. private var credits:HBox;
  34. private var offset:uint = 50;
  35. private var label:Label;
  36.  
  37. override protected function addChildren():void {
  38.  
  39. // load image with smoothing not applied
  40. image = new Loader();
  41. image.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void {
  42. (image.content as Bitmap).smoothing = false;
  43. });
  44. image.load(new URLRequest(CONTENT_URL));
  45.  
  46. // create zoom panel with image as content
  47. zoomPanel = new ZoomPanel();
  48. zoomPanel.content = image;
  49. addChild(zoomPanel);
  50.  
  51. // create HBox to hold controls
  52. controls = new HBox(this);
  53.  
  54. // create controls
  55. new PushButton(controls, 0, 0, "Home", function():void {
  56. zoomPanel.panTo(0, 0);
  57. });
  58. new PushButton(controls, 0, 0, "<<--", function():void {
  59. zoomPanel.panLeft();
  60. });
  61. new PushButton(controls, 0, 0, "-->>", function():void {
  62. zoomPanel.panRight();
  63. });
  64. new PushButton(controls, 0, 0, "/\\", function():void {
  65. zoomPanel.panUp();
  66. });
  67. new PushButton(controls, 0, 0, "\\/", function():void {
  68. zoomPanel.panDown();
  69. });
  70. myZoomSlider = new HSlider(controls, 0, 5, doZoom);
  71. myZoomSlider.tick = 0.25;
  72. myZoomSlider.minimum = 0.25;
  73. myZoomSlider.maximum = 7;
  74. myZoomSlider.value = 1;
  75.  
  76. addChild(controls);
  77.  
  78. zoomPanel.dragZoomControl.minZoom = .25;
  79. zoomPanel.dragZoomControl.maxZoom = 7;
  80.  
  81. zoomPanel.zoomContent.cacheAsBitmap = true;
  82.  
  83. // create HBox to hold credits
  84. credits = new HBox(this);
  85.  
  86. // create credits
  87. var labelText:String = "Van Gogh - Starry Night - 1889 -";
  88. labelText += "(source http://www.flickr.com/photos/financialaidpodcast/3956763480/)";
  89. label = new Label(credits, 0, 0, labelText);
  90.  
  91. new PushButton(credits, 0, 0, "Image Source", getSource);
  92.  
  93. }
  94.  
  95. private function getSource(e:MouseEvent):void {
  96. var link:String = "http://www.flickr.com/photos/financialaidpodcast/3956763480/";
  97. Web.getURL(link, "_blank");
  98. }
  99.  
  100. private function doZoom(event:Event):void {
  101. zoomPanel.zoom = myZoomSlider.value;
  102. }
  103.  
  104. /**
  105. * Applets are resized when stage size changes, so re-center content during redraw
  106. */
  107. override protected function draw():void {
  108. zoomPanel.move(offset, offset);
  109. zoomPanel.setSize(width * .85, height * .85);
  110. controls.x = offset;
  111. controls.y = offset / 2;
  112. credits.x = offset;
  113. credits.y = height * .95;
  114. }
  115. }
  116. }

Category: Code Examples, Flash | One Comment

PV3D InteractivePlanesBoard for Flash CS3

Monday, June 15th, 2009 | Author:

cs3 board image

InteractivePlanesBoard from here converted to work in Flash CS3.

view swf here and download .fla and source here

Icon by http://dryicons.com and pop up view of the swf is displayed using shadowbox.

Category: Code Examples, Flash, Papervision 3D | 3 Comments

Flash CS4 Papervision example

Tuesday, April 07th, 2009 | Author:

This post is mainly to cover some of the questions often asked and give a simple download to try out.

The Papervision examples here were compiled using the Flex SDK and FlashDevelop so there are no .fla’s used. But as the examples are AS3 classes the conversion to using in Flash can be made so here is one download with a few usage ideas.

It was made in Flash CS4 and can be viewed here and the source can be downloaded here. It uses the very simple PlaneDemo class without editing it and the recent Papervision classes Papervision3D_2.0.883.zip from here are included in the zip.

Some things to note:
- The first line of the PlaneDemo class is
package com.dehash.pv3d.examples.basic
so the PlaneDemo class is stored in the following location
com/dehash/pv3d/examples/basic/PlaneDemo.as

- PlaneDemo.as is used as the document class and set in the Publish Properties pane which is one of the ways to use the class in Flash because PlaneDemo extends BasicView which extends AbstractView which extends Sprite.

- the Papervision classes are stored in the libs folder and that directory is added to the Source path using the Publish Settings > Flash tab path > Settings dialogue.

PlaneDemo.as includes the following Metadata
[SWF(width="800", height="600", backgroundColor="0xffffff")]
Flash CS4 is able to read this and implement it whereas the CS3 IDE was not. There is an article that covers this here

At some point I shall put up a more interesting example than PlaneDemo but it does cover many of the essentials despite being quite basic. The pop up view of the swf is displayed using shadowbox.

Category: Code Examples, Flash, Papervision 3D | One Comment

More Papervision 3D examples with source code

Sunday, January 04th, 2009 | Author:

Added some more Papervision 3D examples with source code.

There are now over 30 and all examples use current Papervision3D GreatWhite from SVN and so far all use BasicView also

Category: Code Examples, Flash, Papervision 3D | 8 Comments