Home

Quick Image Viewer

Thursday, November 26th, 2009 | Author: dehash

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:
  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: dehash

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 | 2 Comments

Flash CS4 Papervision example

Tuesday, April 07th, 2009 | Author: dehash

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, Flex SVG, Flickr API, Papervision 3D, YouTube API | One Comment

More Papervision 3D examples with source code

Sunday, January 04th, 2009 | Author: dehash

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

AS3 Image Slicing

Monday, October 27th, 2008 | Author: dehash

Dynamic slicing of an image example which runs a bit better than I expected it to. Idea from here and image from here


Image Slicing Example

more...

Category: Code Examples, Flash | Leave a Comment

Panning Images

Wednesday, October 22nd, 2008 | Author: dehash

Came up with this which is fun to play with.
Images from here 1 | 2 | 3 | 4

Category: Code Examples, Flash | Leave a Comment

Papervision AS3DMod – modifier for 3D Flash

Thursday, September 04th, 2008 | Author: dehash

Modified Cube example using AS3DMod Interested to see this appear yesterday at everydayflash.com and made a quick start on a sandbox for it to get ideas on how to use it with Papervision.

A first example of AS3DMod which is a sandbox to experiment with can be found here.

Updates: Some usage tips noted for the initial version of the library using pv3d

* Seems to work fine with current SVN build of PV3D

* in com.as3dmod.modifiers.Noise.as comment out line 9:
import alternativa.types.Matrix3D; (the import is not used but will error if you only have pv3d library)

* Grab com.carlcalderon.arthropod.Debug.as from here and put it in your path as it is used in several of the files.

* Added simplfied usage code to the example here

* Added examples below using svn build.

Noise - sandpaper to mountain range: AS3DModNoise.as


Taper- rip and shrink: AS3DModTaper.as

Fish example
An idea for a Fish


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

Papervision 3D Examples Added With Source Code

Wednesday, August 06th, 2008 | Author: dehash

Added some more Papervision 3D examples with source code.
All examples use current Papervision3D GreatWhite from SVN and so far all use BasicView also. **Update:** added four more examples to the top of the list to make 18 in total:
PV3D Examples


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

Flex YouTube API Example Feed + Search Display

Wednesday, June 18th, 2008 | Author: dehash

Flex YouTube API feed + search display. download source code here

Uses library @ as3-youtube-data-api

Nice player example @ on_the_other_hand

author of as3-youtube-data-api has a blog @ blog.martinlegris.com

update: added in a simple player to view the movies.

.
Update 2: Added source code download for the feed display
We are making a Cairngorm version of this but here is a simple component version to test.
The source code for the feed display component (not the player) is here
It is a FlashDevelop3 Beta7 project file and uses the Flex3 SDK to compile. To build the project requires the as3-youtube-data-api library Just download youtube-google-0.95.zip and add it to the project path and compile, that is it.

All of the hard work is done by SimpleFeedGrabberExample.as which uses the excellent as3-youtube-data-api library to load feeds from YouTube and parses them into an ArrayCollection which is the Bindable datasource for the display. This is a simple version that will likely change a lot when it is in our Cairngorm project but works fine for now.
as3-youtube-data-api notes: in strict mode you get a few warnings of variables declared without datatypes in the as3-youtube-data-api library but these are easy to fix. Also YouTubeClient has been removed in the library version released yesterday but we substituted YouTubeFeedClient in its place and that seems to work ok.

---
Once the above is complete to integrate with into the otoh player grab the source code from here:
* copy the src directory into this project src folder
* make YouTubeTest.mxml the target file + make 3 edits to it:
* put xmlns:ytfeeds="ytfeeds.*" in the Application tag at the top
* put <ytfeeds:YTFeedComponent top="325" /> just before </mx:Application>
* insert your YouTube Developer key into YouTubeTest.mxml and compile.

Now when you click on a movie in the display it can be played in the otoh player because video.text is set to the selected movie ID.

Update:
Added a Comments viewer, and a related movies tab using the as3-youtube-data-api

View the updated flex youtube movie here

Category: Code Examples, Flash, YouTube API | 12 Comments