Recent News

debug snippet to check whether the client is local or online

Posted by sortofme on September 26th, 2008

often you need different settings whether you are working within your IDE environment during development, or when the swf is actually put LIVE. I have tried many variants of passing DEBUG=true or similar, but found that this one is the most elegant one:

Actionscript:
  1. //checking whther client is online or within IDE
  2.             if(stage.loaderInfo.url.indexOf("file:") != -1){
  3.                 trace("Lokal");
  4.                 _debug = true;
  5.             }else {
  6.                 trace("Server");
  7.                 _debug = false;
  8.             }

loading external images

Posted by sortofme on August 5th, 2008

quick recollection of best practices when loading an image (or any asset) into a flash movie from an external location.

Actionscript:
  1. import flash.display.Loader;
  2. import flash.display.MovieClip;
  3. import flash.events.Event;
  4. import flash.events.IOErrorEvent;
  5. import flash.net.URLRequest;
  6.  
  7. private function ldImage(imagePath:String) {
  8.     throwAlert("loading " + imagePath);
  9.     var _loader:Loader = new Loader();
  10.     _loader.contentLoaderInfo.addEventListener(Event.INIT, onLdInit);
  11.     _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR  , onLdError);
  12.     _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLdComplete);
  13.     var urequest:URLRequest = new URLRequest(imagePath);
  14.     _loader.load(urequest);
  15.     addChild(_loader)
  16. }
  17. private function onLdError(e:Event) {
  18.     trace(this+" !!! onLoad ERROR !!!\n"+e);
  19. }
  20. private function onLdInit(e:Event) {
  21.     trace(e + " onLod Init");
  22. }
  23. private function onLdComplete(e:Event) {
  24.     trace(e + " onLdComplete");
  25. }

flash full browser with swfObject 2

Posted by sortofme on July 9th, 2008

Having had difficulties to find a rather complete description on this very common subject, I thought I might as well compile a selection of techniques necessary to accomplish this.

first, let's go through the requirements within the HTML page and the swfObject javascript, which comes into the head of the HTML page embedding the swf:
more about the use of the swfObject here-->

HTML:
  1. <script type="text/javascript" src="js/swfobject.js"></script>
  2.     <script type="text/javascript"> 
  3.         //vars and parameters for embedded swf
  4.         var flashvars = { };
  5.         var params = { menu: "false", allowScriptAccess:"sameDomain", allowfullscreen :"true"};
  6.         var attributes = { id: "main", name: "main" };
  7.         swfobject.embedSWF("flash/main.swf", "mainFlash", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes); 
  8.     </script>
  9. <style type="text/css">
  10. <!--
  11.   html, body, #mainFlash{ height:100%; width:100%;}
  12.   body { margin:0; padding:0; overflow:hidden; background-color:#A31724; text-align:center; }
  13. -->
  14. </style>

    Set both the width and height of your SWF to 100% in your SWFObject definition.
    Include CSS to get rid of any default margins/padding and set the height of the html element, the body element and the entire chain of block level HTML elements that your SWF will be nested in to 100%, because Firefox (or: any Gecko based browser) in standards compliant mode (or: using a valid DOCTYPE) interprets percentages in a very strict way (to be precise: the percentage of the height of its parent container, which has to be set explicitly)

Now go to your flash movie, and manage the scaling and alignment of your SWF and the positioning of your SWF's elements, within your ActionScript code, e.g.:

Actionscript:
  1. stage.scaleMode = StageScaleMode.NO_SCALE;
  2. stage.align = StageAlign.TOP_LEFT;
  3.  
  4. stage.addEventListener(Event.RESIZE, resizeHandler);
  5.  
  6. function resizeHandler(event:Event):void {
  7.    trace(stage.stageWidth + " x " + stage.stageHeight);
  8.   // center stuff
  9. }

looping video in AS3

Posted by sortofme on April 30th, 2008
Actionscript:
  1. <pre>
  2. package {
  3.  
  4.     import com.onebyonedesign.extras.VideoLoop;
  5.     import flash.display.Sprite;
  6.     import flash.events.AsyncErrorEvent;
  7.     import flash.events.Event;
  8.     import flash.events.MouseEvent;
  9.     import flash.text.AntiAliasType;
  10.     import flash.text.TextField;
  11.     import flash.text.TextFieldAutoSize;
  12.     import flash.text.TextFormat;
  13.     import flash.text.TextFormatAlign;
  14.  
  15.     public class Main extends Sprite {
  16.  
  17.         private var isPlaying:Boolean = true;
  18.         private var videoLoop:VideoLoop;
  19.  
  20.         public function Main():void {
  21.             videoLoop = new VideoLoop("water.flv");
  22.             videoLoop.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);
  23.             addChild(videoLoop);
  24.  
  25.             stage.addEventListener(MouseEvent.CLICK, adjustVideo);
  26.  
  27.             var info:TextField = new TextField();
  28.             info.selectable = false;
  29.             info.autoSize = TextFieldAutoSize.LEFT;
  30.             info.antiAliasType = AntiAliasType.ADVANCED;
  31.             var fmt:TextFormat = new TextFormat("_sans", 12, 0x939393);
  32.             fmt.align = TextFormatAlign.CENTER;
  33.             info.defaultTextFormat = fmt;
  34.             info.text = "Two second video looped.\nClick to pause/resume.";
  35.             info.x = 95;
  36.             info.y = 190;
  37.  
  38.             addChild(info);
  39.         }
  40.  
  41.         private function onAsyncError(aee:AsyncErrorEvent):void {
  42.             //  handle annoying async errors (such as the missing metadata property) here.
  43.         }
  44.  
  45.         private function adjustVideo(me:MouseEvent):void {
  46.             if (isPlaying) {
  47.                 videoLoop.pause();
  48.             } else {
  49.                 videoLoop.play();
  50.             }
  51.             isPlaying = !isPlaying;
  52.         }
  53.     }
  54. }</pre>

capture Jpeg live from webcam

Posted by sortofme on April 29th, 2008

For one of my projects that let's the user record a profile video through his webcam, I need to publish a JPEG from the recorded video to later display in an html video list.
After turning the web upside down, I found that byteArrays blog's approach seemed the most suitable one. But he works with AMFPHP, which I did not want to add to the other frameworks already involved with this project, and therefor reconstructed it using a simple PHP solution.
I will continue posting my progress here, and offer src files ASAP.

Another source I found, but haven't evaluated yet, because it is built in AS2, works with PHP's GD image library.

For more information on AMFPHP (aka flash remoting for PHP), which is a remoting service for flash applications, that basically allows flash movies to call remote server side applications. Here is an introduction, but I think that it deserves it's own topic in flashcrobat. I hopefully will soon have time to look deeper into it.

<update >

Ok I have come closer :

http://labs.findsubstance.com/2008/04/03/as3-upload-encode-images/

and :

http://www.hackszine.com/blog/archive/2008/04/encoding_jpegs_clientside_in_a.html

http://henryjones.us/articles/using-the-as3-jpeg-encoder

I am going to try to combine the infos found on several resources, and hope that as an outcome we will have a nice reusable application with which you can make a thumbnail of a clip recorded through your webcam. So let's spit in our hands:

AS3 clipboard functionality

Posted by sortofme on April 23rd, 2008

The System.setClipboard() method allows a SWF file to replace the contents of the clipboard with a plain-text string of characters. This poses no security risk. To protect against the risk posed by passwords and other sensitive data being cut or copied to clipboards, there is no corresponding "getClipboard" (read) method.

Flash and JavaScript

Posted by sortofme on April 21st, 2008

I will here collect a series of links of useful information on the interaction between flash and JavaScript, Until I have evaluated all relevant infos, to write a good summary on common practices.

  • SWFObject has grown up! version 2.0
    • static
    • dynamic
  • The famous SWFObject to easily embed flash content in html, that was previously hosted on deconcept.com has now moved to google.code basically there are 2 ways to embed your swf into your HTML site:

    Following is a basic code sample for the integration using swf object, including parameters, flashvars and attributes. (for many external interface interactions, you will need to give your swf an ID and a name)
    here the javascipt to embed, in this case for a fullBrowser embed of the swf:

    
    
    JavaScript:
    1. <script src="js/swfobject.js" type="text/javascript"></script>
    2. <script type="text/javascript">
    3.  
    4.         //vars and parameters for embedded swf
    5.         var flashvars = {var1:"sampleImg.jpg", var2:"my caption here"};
    6.         var params = { menu: "false", allowScriptAccess:"sameDomain",allowfullscreen :"true"};
    7.         var attributes = { id: "mainSwf", name: "mainSwf" };
    8.         swfobject.embedSWF("flash/main.swf", "mainSwfDiv", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes);
    9. </script>
    10. <!-- later in the html page comes the div tag where you want your swf to be embedded where you can put in your alternative text, in case someone has javascript disabled, or no flash plugin installed.-->
    11. <div id="mainSwfDiv">
    12.  You need Javascript activated and the flash player plugin installed to be able to view this content.
    13. The newest Flash Player can be downloaded here:
    14.  
    15. <a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></div>

    Attention!!:
    giving the id or the name identical name to the swf file causes javascript errors on IE!! took me ages to find the reason for these. So just call your id and name differently than your swf is called.

  • Passing variable from JavaScript To AS3
  • A brief and basic recollection about passing vars from JS to AS3. found on: metah.ch

    <updated 04.08.2008>

    After having passed on variables inside of the swfObject script in my HTML/PHP page:

    Actionscript:
    1. //in the HTML:
    2. var flashvars = {var1:"sampleImg.jpg", var2:"my caption here"};
    3. // If you want to retrieve these vars later within your flash App:
    4. var myImagePath:String = this.loaderInfo.parameters.var1;
    5.  
    6. //to  trace all the variables (names and values) passed to the Flash Player:
    7. for ( var theName:String in this.loaderInfo.parameters ) {
    8.    var theValue:String = this.loaderInfo.parameters [theName];
    9.    trace("from JS :"+ theName+" "+theValue);
    10. }

    Read the rest of this entry »

    Instance Class or Superclass name: getQualifiedClassName()

    Posted by sortofme on March 11th, 2008

    sometimes, you want to know the instances class name or the superclass's name. AS3 offers a new function called getQualifiedClassName (flash.utils.getQualifiedClassName) to do just that:

    Actionscript:
    1. var sprite:Sprite = new Sprite();
    2. trace(getQualifiedClassName(sprite)); // "flash.display::Sprite"
    3.  
    4. //or to retrieve the name of the super class, use:
    5. trace(getQualifiedSuperclassName(sprite)); // "flash.display::DisplayObjectContainer"

    If you actually want to sieve through plenty of info about your instance, try describeType() (flash.utils.describeType).

    Actionscript:
    1. var sprite:Sprite = new Sprite();
    2. var spriteDescription:XML = describeType(sprite);
    3. trace (spriteDescription);

    try to see....(loads of data coming out here...)

    what also fits in here is the use ofgetDefinitionByName()(flash.utils.getDefinitionByName).

    avoid new window blocked by Firefox/IE

    Posted by sortofme on March 6th, 2008

    How annoying! You have your flash application, make a normal external link (a good old www basic), and then the browsers block your external link!, well there seems to be a work around:

    Actionscript:
    1. function getURL(url:String,window:String="_blank"):void{
    2.     var broswer:String=ExternalInterface.call("function getBrowser(){return navigator.userAgent}") as String;
    3.     if(broswer.indexOf("Firefox")!=-1 || broswer.indexOf("MSIE 7.0")!=-1){
    4.         ExternalInterface.call('window.open("'+url+'","'+window+'")');
    5.     }else{
    6.         navigateToURL(new URLRequest(url),window);
    7.     }
    8. }

    and the most important is set the wmode property is opaque or transparent.

    courtesy of:
    http://www.riaidea.com/article.asp?id=27(chinese Blog)

    Somehow getURL() survived the AS3 code cull, an interesting approach to make it reusable can be found here on Steven Sacks blog. cheers for that one. Would be interesting to combine them to one. TODO:)

    passing parameters to Events, custom events

    Posted by sortofme on February 29th, 2008

    In AS 3.0, if you do want to pass params in your Events you can create your own custom events:

    update 12.08.08:
    I have updated the class to be able to carry any kind of parameters, in an array, making it more flexible.

    Actionscript:
    1. package com.events {
    2.    
    3.     /**
    4.     * ...CustomEvent class
    5.     * to attach params to dispatch event in arg:Array
    6.     * @author Sim   15/03/2008 22:56
    7.     * @usage    import com.events.CustomEvent;
    8.     *       var myCustomEvnt = new CustomEvent("EventName",parameterArray);
    9.                 dispatchEvent(myCustomEvnt);
    10.                 // OR simpler:
    11.                 dispatchEvent(new CustomEvent("EventName",parameterArray));
    12.                
    13.     */
    14.     import flash.events.Event;
    15.    
    16.     public class CustomEvent extends  Event {
    17.        
    18.         public var arg:*;
    19.        
    20.         public function CustomEvent( type:String, ... a:*) {
    21.             super( type );
    22.             arg = a;
    23.         }
    24.         override public function clone():Event{
    25.             return new CustomEvent( type, arg );
    26.         }
    27.     }
    28. }
    29.  
    30. /*_______you then dispatch this like this______*/
    31.  
    32. //you would have to import your custom event
    33. import com.events.CustomEvent;
    34. var myCustomEvnt = new CustomEvent("EventName","1","2","3");
    35.                 dispatchEvent(myCustomEvnt);
    36.  
    37. //again you would need to import your custom event
    38. import com.events.CustomEvent;
    39. hboxvar.addEventListener( "EventName", dosomething );
    40.  
    41. private function dosomething( event:CustomEvent ):Void{
    42.     trace( event.arg) // output: 1,2,3
    43. }

    another interesting approach can be found here, where flep assigns multiple event types to one custom event, to have more variety in eventHandling.

    Recent Comments | Recent Posts


    designed and coded by: noesi
    bottom