Archive for November, 2007

Busy Time

I apologize for the lack of posting in the past two weeks. I’m in the process of purchasing a home and it has sucked all my free time up from meeting with all kinds of people to doing research to make sure I’m not getting talked into something I don’t understand to having to drive back and forth and dropping off paperwork. I will luckily be out in Montego Bay, Jamaica from the 8th to the 15th to give me some time to recuperate and then of course we have the holidays, but posting should resume to normal sometime between then. So get your holiday shopping done and enjoy the rest of 2007.

Tags: ,

AIR: Making Draggable Windows

Download Example Files

I've recently been working on my first AIR project and one of the things it had to include was dragging around your desktop with a transparent chrome (meaning there is no minimize/close/etc buttons). It is really simple to do in AIR (one line of code to do the actual dragging) so here it is:

Actionscript:
  1. box_mc.addEventListener(MouseEvent.MOUSE_DOWN, doMouseDown);
  2.  
  3. function doMouseDown($evt:MouseEvent):void
  4. {
  5.     this.stage.nativeWindow.startMove();
  6. }

Keep in mind AIR is all AS3 so there is no AS2 alternative for this method. Also make sure to set up your file to output the transparent chrome by going to Commands > AIR Application & Installer Settings (if you've followed my tip on how to set AIR up in Flash CS3) and change the Window style to Custom Chrome (transparent).

Tags: , ,

Setting Up AIR For Flash CS3

To get up and running with AIR (Adobe Integrated Runtime) you don't really have to do very much. Adobe has provided an installer to update Flash CS3 to be able to make AIR applications directly in the Flash IDE. All you've got to do is go download it here. Make sure that before you install this update, you have the Adobe AIR runtime installed which allows you to run AIR applications on your computer (kind of like the Flash Player). Grab that first here.

So what does this update do? Basically, as stated before, it allows you to create/publish AIR applications in the Flash IDE. You will notice on your start page for Flash CS3 that you now have an option, under the Create New column, to select Flash File (Adobe AIR). This automatically sets the publish settings to publish to AIR. Once you do this, a little popup box will show that you are Authoring for AIR with Flash CS3 in which you can just click OK. If you now look in your Commands dropdown you will see two new options: AIR - Application and Installer Settings and AIR - Create AIR File. The first option allows you to set the properties of your AIR movie anywhere from naming it to the window style you want to use to which files to include in the package. You will also have to create a Digital signature file for your project or you will get an ugly AIRI file when you publish which is pretty much useless.

To create the signature, just click Set, then click Create and put in your information for the fields. This information, as far as I know, is pretty meaningless but fill it out however you'd like. Make sure to set a password and save the file. When you click OK, you will be taken back to the previous prompt and you'll have to put in the password you set when you created the certificate. Then click OK and you're all done.

The second command brings up a certificate creation prompt in which you should just have to enter your password and be all set. Keep in mind that you can actually package the AIR file in the first command we discussed so you may never actually have to use the second one.

Lastly, if you want to see your output traces, make sure you are using Debug > Debug Movie. If you don't, your traces will never get called and you won't see what is going on with your application.

That is all you should need to get up and running with AIR in Flash CS3. There is more and more AIR resources becoming available on the net and a bunch of books coming out in 2008 on the topic to help us all out.

Tags: , ,

Foundation Flash 8 Video Review

Original Publish Date: 10/20/2006

Author(s): Jordan Chilcott, Tom Green
Paperback: 360 pages
Publisher: friends of ED (June 19, 2006)
ISBN: 159059651X
Overall Score: 3/5

As someone who has been working with video in Flash quite heavily recently at work, I was eagerly anticipating this book to be released. At first I wasn't disappointed as the book has a great intro to video. It goes through a relatively thorough explanation of video and how it works on the net, talking about progressive and streaming downloading, and so on. As the title suggests, this book is a Foundation book so it is not code heavy and is perfect for beginners.

There is a chapter in the book about editing video, which if it is out of the scope of the book or not, is a very handy chapter. Not everyone in the world could afford huge software packages like Final Cut Pro and Adobe Premiere (or After Effects, depends on how you like to do things I suppose). This chapter goes over how to edit video with some of the tools that come shipped with your OS, whether it be iMovie on OSX or Windows Movie Maker on PC.

Getting back to the whole code thing, as an ActionScript developer I sometimes get let down by not seeing a lot of code (although it really depends on how you see things, because not everyone is nerdy like me and would rather not sift through code and just do things a different way). Page 186 clearly warns that this book is about Flash video, not ActionScript programming, but I believe when doing video you HAVE to know how to code around it. I see some video apps on the web today and all they have is the default FLVPlayback component skin on them. That's fine and dandy, but those things are ugly and everyone who knows how they were made just laughs at them.

Chapter 9 and chapter 11 get a bit more code heavy and even into some class programming, but the coding done throughout those chapters is geared more towards applying code to the video that make its stylized, a la blend modes and filters. To me, when I see a book on Flash video, I want to learn the ins and outs of controlling the video and making it do things like play videos in sequence, loading in the background, so on and so forth. I already know how to use blending modes and filters from the other great Friends of ED books (Flash 8 Essentials).

All in all, this really is a beginner book on video and if you're looking for a way to learn to control your videos thoroughly in and out, you won't find it here. If you just want to add some effects to your videos, this is the book for you.

Tags: , , , ,

AS3: DistortionTweener

View Example 1
View Example 2
View Example 3
View Documentation
Download Class & Example Files

The DistortionTweener allows you to distort four points of an object. It is an easy to way make distortions such as trapezoids on a movie clip.

The DistortionTweener uses Ruben Swieringa's DistortImage class and is based on a sample .FLA provided by Tam Ho on how to use DistortImage in Flash.

Actionscript:
  1. /**
  2. * The DistortionTweener allows you to distort four points of an object. It is an easy to way make distortions such as trapezoids on a movie clip.
  3. *
  4. * The DistortionTweener uses Ruben Swieringa's DistortImage class (http://www.rubenswieringa.com/blog/distortimage) and is based on a sample .FLA provided by Tam Ho (http://www.flashteam.com.au) on how to use DistortImage in Flash.
  5. *
  6. * @usage
  7. * <code>
  8. * <pre>
  9. import com.reintroducing.transitions.DistortionTweener;
  10. import fl.transitions.easing.Regular;
  11. var dt:DistortionTweener = new DistortionTweener(s, clip_mc, tl, tr, br, bl, 5);
  12. dt.addEventListener(Event.INIT, onDistortStarted);
  13. dt.addEventListener(Event.COMPLETE, onDistortFinished);
  14. dt.tweenTo(new Point(-50, -50), new Point(410, -50), new Point(310, 266), new Point(50, 266), Regular.easeIn, .5);
  15. // fired off when the distortion tween starts
  16. function onDistortStarted($evt:Event):void
  17. {
  18.     trace("Starting the distortion.");
  19. }
  20. // fired off whent he distortion tween ends
  21. function onDistortFinished($evt:Event):void
  22. {
  23.     trace("Finished the distortion.");
  24. }
  25. * </pre>
  26. * </code>
  27. *
  28. * @author Matt Przybylski [http://www.reintroducing.com]
  29. * @version 1.0
  30. */
  31.  
  32. package com.reintroducing.transitions
  33. {
  34.     import flash.display.Bitmap;
  35.     import flash.display.BitmapData;
  36.     import flash.display.MovieClip;
  37.     import flash.display.Shape;
  38.     import flash.events.Event;
  39.     import flash.events.EventDispatcher;
  40.     import flash.geom.Point;
  41.    
  42.     import org.flashsandy.display.DistortImage;
  43.    
  44.     import fl.transitions.Tween;
  45.     import fl.transitions.TweenEvent;   
  46.  
  47.     public class DistortionTweener extends EventDispatcher
  48.     {
  49. //- PRIVATE & PROTECTED VARIABLES -------------------------------------------------------------------------
  50.  
  51.         private var _holder:*;
  52.         private var _mc:MovieClip;
  53.         private var _mcWidth:Number;
  54.         private var _mcHeight:Number;
  55.         private var _bmd:BitmapData;
  56.         private var _bmp:Bitmap;
  57.         private var _container:Shape;
  58.         private var _tl:Point;
  59.         private var _tr:Point;
  60.         private var _br:Point;
  61.         private var _bl:Point;
  62.         private var _distortion:DistortImage;
  63.         private var _tweenFunc:Function;
  64.         private var _tweenTime:Number;
  65.         private var _precision:uint;
  66.        
  67.         // tweens
  68.         private var _tlXTween:Tween;
  69.         private var _tlYTween:Tween;
  70.         private var _trXTween:Tween;
  71.         private var _trYTween:Tween;
  72.         private var _brXTween:Tween;
  73.         private var _brYTween:Tween;
  74.         private var _blXTween:Tween;
  75.         private var _blYTween:Tween;
  76.        
  77. //- PUBLIC & INTERNAL VARIABLES ---------------------------------------------------------------------------
  78.        
  79.         public static const DEFAULT_NAME:String = "com.reintroducing.transitions.DistortionTweener";
  80.        
  81. //- CONSTRUCTOR -------------------------------------------------------------------------------------------
  82.    
  83.         /**
  84.          * Creates a new instance of the DistortionTweener class.  The point values are relative to the holder clip, NOT the stage.
  85.          *
  86.          * @usage <pre><code>var dt:DistortionTweener = new DistortionTweener($holder, $mc, $tl, $tr, $br, $bl, $precision);</code></pre>
  87.          *
  88.          * @param $holder The DisplayObject that will be used to hold your distorted bitmap
  89.          * @param $mc The source movie clip that will be used to copy into the bitmap that will be distorted
  90.          * @param $tl The top left point to use in the distortion
  91.          * @param $tr The top right point to use in the distortion
  92.          * @param $br The bottom right point to use in the distortion
  93.          * @param $bl The bottom left point to use in the distortion
  94.          * @param $precision A uint representing the value to use as the precision in the DistortImage class
  95.          */
  96.        
  97.         public function DistortionTweener($holder:*, $mc:MovieClip, $tl:Point, $tr:Point, $br:Point, $bl:Point, $precision:uint):void
  98.         {
  99.             this._holder    = $holder;
  100.             this._mc       = $mc;
  101.             this._mcWidth   = this._mc.width;
  102.             this._mcHeight  = this._mc.height;
  103.             this._tl       = $tl;
  104.             this._tr       = $tr;
  105.             this._br       = $br;
  106.             this._bl       = $bl;
  107.             this._precision = $precision;
  108.            
  109.             this.init();
  110.         }
  111.        
  112. //- PRIVATE & PROTECTED METHODS ---------------------------------------------------------------------------
  113.        
  114.         private function init():void
  115.         {
  116.             this._mc.visible = false;
  117.            
  118.             this._bmd     = new BitmapData(this._mcWidth, this._mcHeight, true, 0x00FFFFFF);
  119.             this._bmd.draw(this._mc);
  120.            
  121.             this._bmp     = new Bitmap(this._bmd);
  122.             this._container = new Shape();
  123.            
  124.             this._holder.addChild(this._container);
  125.            
  126.             this._distortion = new DistortImage(this._mcWidth, this._mcHeight, this._precision, this._precision);
  127.             this._distortion.setTransform(this._container.graphics, this._bmp.bitmapData, this._tl, this._tr, this._br, this._bl);
  128.         }
  129.  
  130. //- PUBLIC & INTERNAL METHODS -----------------------------------------------------------------------------
  131.    
  132.         /**
  133.          * Tweens the distortion. As with the constructor, the point values are relative to the holder clip, NOT the stage.
  134.          *
  135.          * <p>
  136.          * The tweenTo method dispatches two events:
  137.          * <ul>
  138.          * <li>Event.INIT: Dispatched when the tweening begins</li>
  139.          * <li>Event.COMPLETE: Dispatched when the tweening ends</li>
  140.          * </ul>
  141.          * </p>
  142.          *
  143.          * @usage <pre><code>dt.tweenTo(new Point(-50, -50), new Point(410, -50), new Point(310, 266), new Point(50, 266), Regular.easeIn, .5);</code></pre>
  144.          *
  145.          * @param $tl The top left point to end the tween at
  146.          * @param $tr The top right point to end the tween at
  147.          * @param $br The bottom right point to end the tween at
  148.          * @param $bl The bottom left point to end the tween at
  149.          * @param $tweenFunc The easing function to use in the tween
  150.          * @param $time The duration, in seconds, of the tween
  151.          *
  152.          * @return Nothing
  153.          */
  154.        
  155.         public function tweenTo($tl:Point, $tr:Point, $br:Point, $bl:Point, $tweenFunc:Function, $time:Number):void
  156.         {
  157.             this.dispatchEvent(new Event(Event.INIT));
  158.            
  159.             this._tweenFunc = $tweenFunc;
  160.             this._tweenTime = $time;
  161.            
  162.             // top left tweens
  163.             this._tlXTween = new Tween(this._tl, "x", this._tweenFunc, this._tl.x, $tl.x, this._tweenTime, true);
  164.             this._tlYTween = new Tween(this._tl, "y", this._tweenFunc, this._tl.y, $tl.y, this._tweenTime, true);
  165.            
  166.             // top right tweens
  167.             this._trXTween = new Tween(this._tr, "x", this._tweenFunc, this._tr.x, $tr.x, this._tweenTime, true);
  168.             this._trYTween = new Tween(this._tr, "y", this._tweenFunc, this._tr.y, $tr.y, this._tweenTime, true);
  169.            
  170.             // bottom right tweens
  171.             this._brXTween = new Tween(this._br, "x", this._tweenFunc, this._br.x, $br.x, this._tweenTime, true);
  172.             this._brYTween = new Tween(this._br, "y", this._tweenFunc, this._br.y, $br.y, this._tweenTime, true);
  173.            
  174.             // bottom left tweens
  175.             this._blXTween = new Tween(this._bl, "x", this._tweenFunc, this._bl.x, $bl.x, this._tweenTime, true);
  176.             this._blYTween = new Tween(this._bl, "y", this._tweenFunc, this._bl.y, $bl.y, this._tweenTime, true);
  177.            
  178.             this._blYTween.addEventListener(TweenEvent.MOTION_CHANGE, render);
  179.             this._blYTween.addEventListener(TweenEvent.MOTION_FINISH, onFinished);
  180.         }
  181.        
  182.         /**
  183.          * Resets the bitmap to the specified points.
  184.          *
  185.          * @usage <pre><code>dt.reset(new Point(0, 0), new Point(clip_mc.width, 0), new Point(clip_mc.width, clip_mc.height), new Point(0, clip_mc.height));</code></pre>
  186.          *
  187.          * @param $tl The top left point to use in the distortion
  188.          * @param $tr The top right point to use in the distortion
  189.          * @param $br The bottom right point to use in the distortion
  190.          * @param $bl The bottom left point to use in the distortion
  191.          *
  192.          * @return Nothing
  193.          */
  194.        
  195.         public function reset($tl:Point, $tr:Point, $br:Point, $bl:Point):void
  196.         {
  197.             this._tl = $tl;
  198.             this._tr = $tr;
  199.             this._br = $br;
  200.             this._bl = $bl;
  201.            
  202.             this._container.graphics.clear();
  203.             this._holder.removeChild(this._container);
  204.            
  205.             this._container = null;
  206.             this._container = new Shape();
  207.            
  208.             this._holder.addChild(this._container);
  209.         }
  210.        
  211.         /**
  212.          * Cleans up the DistortionTweener for garbage collection.
  213.          *
  214.          * @usage <pre><code>dt.destroy();</code></pre>
  215.          *
  216.          * @return Nothing
  217.          */
  218.        
  219.         public function destroy():void
  220.         {
  221.             this._bmd.dispose();
  222.            
  223.             this._container.graphics.clear();
  224.             this._holder.removeChild(this._container);
  225.            
  226.             this._bmd = null;
  227.             this._bmp = null;
  228.             this._container = null;
  229.             this._holder = null;
  230.             this._distortion = null;
  231.         }
  232.    
  233. //- EVENT HANDLERS ----------------------------------------------------------------------------------------
  234.    
  235.         // Dispatched during the MOTION_CHANGE event to update the distorted graphics.
  236.         private function render($evt:TweenEvent):void
  237.         {
  238.             this._container.graphics.clear();
  239.             this._distortion.setTransform(this._container.graphics, this._bmp.bitmapData, this._tl, this._tr, this._br, this._bl);
  240.         }
  241.        
  242.         // Dispatches a COMPLETE event when the distortion is finished.
  243.         private function onFinished($evt:TweenEvent):void
  244.         {
  245.             this._blYTween.removeEventListener(TweenEvent.MOTION_CHANGE, render);
  246.             this._blYTween.removeEventListener(TweenEvent.MOTION_FINISH, onFinished);
  247.            
  248.             this._tlXTween = null;
  249.             this._tlYTween = null;
  250.             this._trXTween = null;
  251.             this._trYTween = null;
  252.             this._brXTween = null;
  253.             this._brYTween = null;
  254.             this._blXTween = null;
  255.             this._blYTween = null;
  256.            
  257.             this.dispatchEvent(new Event(Event.COMPLETE));
  258.         }
  259.    
  260. //- GETTERS & SETTERS -------------------------------------------------------------------------------------
  261.    
  262.        
  263.    
  264. //- HELPERS -----------------------------------------------------------------------------------------------
  265.    
  266.         public override function toString():String
  267.         {
  268.             return "com.reintroducing.transitions.DistortionTweener";
  269.         }
  270.    
  271. //- END CLASS ---------------------------------------------------------------------------------------------
  272.     }
  273. }

Tags: , , ,

AS2: SharedObjectManager

View Documentation
Download Class

A simple utility to manage shared objects and their properties.

Actionscript:
  1. import mx.events.EventDispatcher;
  2. import mx.utils.Delegate;
  3.  
  4. /**
  5. * A simple utility to manage shared objects and their properties.
  6. *
  7. * @usage
  8. * <code>
  9. * <pre>
  10. import com.reintroducing.utils.SharedObjectManager;
  11. var som:SharedObjectManager = new SharedObjectManager("userData");
  12. som.setProperty("hasVisited", "yes");
  13. trace(som.getProperty("hasVisited"));
  14. * </pre>
  15. * </code>
  16. *
  17. * @author Matt Przybylski [http://www.reintroducing.com]
  18. * @version 1.0
  19. */
  20.  
  21. class com.reintroducing.utils.SharedObjectManager
  22. {
  23. //- PRIVATE VARIABLES -------------------------------------------------------------------------------------
  24.     
  25.     private var dispatchEvent:Function;
  26.    
  27.     private var _so:SharedObject;
  28.    
  29. //- PUBLIC VARIABLES --------------------------------------------------------------------------------------
  30.    
  31.     public static var DEFAULT_NAME:String = "com.reintroducing.utils.SharedObjectManager";
  32.    
  33.     public var addEventListener:Function;
  34.     public var removeEventListener:Function;
  35.    
  36. //- CONSTRUCTOR -------------------------------------------------------------------------------------------
  37.    
  38. <