Flash

Spartacus Widget


[…]

Published on Fri, 05 Mar 2010 22:14

TiltViewer

Every once in a while i come across a pretty sweet flash/flex application…and what makes TitleViewer really cool is that it’s free and configurable.


[…]

Published on Fri, 22 Feb 2008 02:32

AS3 Reflections Tutorial

Ben Pritchard AKA PixelFumes, put together this cool tutorial for creating AS3 reflections.



I dig that it can also update iself and display video.



http://www.adobe.com/devnet/flash/articles/reflect_class_as3.html


[…]

Published on Wed, 25 Jul 2007 04:09

Unit testing Flex with FlexUnit and Cairngorm - The IResponder interface hurdle

There is an interesting challenge associated with unit testing flex and working with Cairngorm. This is a because Cairngorm commands implement the IResponder interface which returns the remote services response to the result or fault methods, as opposed to dispatching an event.

For example if you run a unit test to asynchronously load an XML file, you can use FlexUnit's built in addAsync() method and wrap it around your xml onData() method with timeout parameter like so:

asyncDispatcher.addEventListener(Event.COMPLETE, addAsync(onData, 2000)); 

This is all fine and dandy, but what happens when you don't have the luxury of listening for a dispatched event?

Well, the answer is actually simple after you see the solution. We came accross a post that led us to the answer. Assuming you have FlexUnit installed, you must add the following method to

TestUnit.as.

public function addResponder(responder : IResponder, timeout : int, passThroughData : Object = null) : IResponder { if (asyncTestHelper == null) { asyncTestHelper = new AsyncTestHelper(this, testResult); } asyncMethods.push({func: responder.result, timeout: timeout, extraData: passThroughData, failFunc: responder.fault, responder: responder}); return asyncTestHelper; } 

Sorry, the code formatting above is a little funky.

Now, make your Test Case. This example is a simple login that gets returned an XML response of true or false.

package test.command { 
import flexunit.framework.TestCase; 
import flexunit.framework.TestSuite; 
import flexunit.framework.*
 import com.jharbs.business.ServiceDelegate; 
import mx.rpc.IResponder; 
public class TestLogin extends TestCase implements IResponder 
{
private var username:String; 
private var password:String; 
public function TestLogin(method:String) 
{ 
super(method); 
} 
override public function setUp():void 
{ 
username = "username"; 
password = "123456"; 
} 
override public function tearDown():void 
{ 
username = null; 
password = null; 
} 
public function login():void 
{ 
var delegate : ServiceDelegate = new ServiceDelegate(this.addResponder(this, 5000)); 
delegate.Login(username, password); }
public function result ( event : Object ) : void 
{ 
// you need to translate your result here. //
}

in this example we are getting xml back // with a boolean true or false

var x : XML = new XML(event.result) 
var bool : Boolean = (x.text()=="true" || x.text()=="false"); 
assertEquals("Invalid Login Result", bool,true); 
} 
public function fault (event : Object ) : void 
{ } 
public static function suite():TestSuite { 
var ts:TestSuite = new TestSuite(); 
ts.addTest( new TestLogin( "login" ) ); 
return ts; } } }

And then of course your can't forget your Cairngorm Application and TestRunnerBase.

<mx:application creationcomplete="onCreationComplete()" xmlns="*" xmlns:business="com.jharbs.business.*" xmlns:control="com.jharbs.control.*" xmlns:flexunit="flexunit.flexui.*" xmlns:mx="http://www.adobe.com/2006/mxml"></mx:application> <mx:script> <!--[CDATA[ import test.command.TestLogin; import flexunit.framework.TestSuite; // After everything is built, configure the test // runner to use the appropriate test suite and // kick off the unit tests private function onCreationComplete():void { testRunner.test = createSuite(); testRunner.startTest(); } // Creates the test suite to run private function createSuite():TestSuite { var ts:TestSuite = new TestSuite(); // TODO: Add more tests here to test more classes // by calling addTest as often as necessary ts.addTest( TestLogin.suite() ); return ts; } ]]--></mx:script> <!-- =========================================================================== 

Cairngorm Service/Controller

<business:services gatewayurl="http://xxx.xxx.xxx.xxx:8180/tiered/jharbs-api/" id="remoting"> 
<control:jharbscontroller id="controller"> 
<flexunit:testrunnerbase height="100%" id="testRunner" width="100%"> 
</flexunit:testrunnerbase>
</control:jharbscontroller>
</business:services>

[...]
Published on Sat, 16 Jun 2007 06:58

Firebug

I ran across Firebug a couple months back. I installed it and didn’t think much of it…this past weekend i ran into a situation where i needed to know certain CSS styles and some Javascript code that were buried in their respective files.



This extension lets you debug, and monitor CSS, HTML, and JavaScript, without having to open the file in an editor or right click and view the page source.



Pretty nice for development.


[…]

Published on Wed, 30 May 2007 04:21

Sending Flash Posts to the Server (AS1)

This example is straight from the docs.



AS1…

 var my_lv:LoadVars = new LoadVars(); my_lv.playerName = playerName_txt.text; my_lv.playerScore = playerScore_txt.text; my_lv.send("setscore.cfm", "_blank", "POST"); 
 var submitListener:Object = new Object(); submitListener.click = function(evt:Object) { var result_lv:LoadVars = new LoadVars(); result_lv.onLoad = function(success:Boolean) { if (success) { result_ta.text = result_lv.welcomeMessage; } else { result_ta.text = "Error connecting to server."; } }; var send_lv:LoadVars = new LoadVars(); send_lv.name = name_ti.text; send_lv.sendAndLoad("<a href="http://www.flash-mx.com/mm/greeting.cfm">http://www.flash-mx.com/mm/greeting.cfm</a>", result_lv, "POST"); }; submit_button.addEventListener("click", submitListener); 


[…]

Published on Thu, 10 May 2007 23:27

Embedding XML in Flex

Here's an example of embedding an XML file, then tracing out data at compile time via actionscript.

The best part is the the XML is compiled into the swf, and you can access any of the XML file's properties by accessing it via the singleton XML Manager.

  [Embed(source="myXMLFile.xml",mimeType="application/octet-stream")] 
public static const XMLFILE:Class; 
public static const MY_XML : XML = setConst(); 
private var cache : Object ;
public var dataXML : XML; 
private static function setConst():XML
{ 
var ba:ByteArray = new XMLFILE() as ByteArray; 
trace("compiling"); 
return new XML(ba.readUTFBytes(ba.length)); 
} 
private static var model : XMLManager; 
public static function getInstance() : XMLManager 
{ 
if ( model == null ) 
{
model = new XMLManager(); 
} 
return model; 
} 
public function XMLManager() 

{ if 
( model != null ) { throw new Error( "Only one XML Manager instance should be instantiated" ); }
 dataXML = MY_XML; cache = new Object(); 
} 

[...]
Published on Fri, 27 Apr 2007 10:58

Save bandwidth costs by stopping FLVs from downloading

I was checking out fulasagoog today and found a posting from Betriebsraum weblog about stopping an FLV from downloading. This not only saves bandwidth costs, but also saves reduces processing power and memory usage. The basic concept is to create a snapshot of the video using the bitmapdata object, overlay this snapshot over the video, hide the video and replace the FLV player's source with a tiny FLV. Utterly brilliant and probalby something that we should be using for Vongo. I am including the code snippet to refer to later, this was originally posted at Betriebsraum blog. (This is not my original work).

Stage.scaleMode = "noScale";
import flash.display.*;
import mx.utils.Delegate;
var flvDummy:String = "dummy.flv";
var flvMovie:String = "trusted_computing.flv";
var snapBmd:BitmapData;
function onFlvReady(evObj:Object):Void {
  switch (fp.contentPath) {
    case flvMovie :
      createSnapshot();
      stopLoading();
    case flvDummy :
      // 
      break;
  }
}
function onFlvProgress(evObj:Object):Void {//
  trace("flv loading: "+fp.contentPath+" "+evObj.bytesLoaded+" "+evObj.bytesTotal);
}
function createSnapshot():Void {
  snapBmd = new BitmapData(fp.width, fp.height, true, 0x00000000);
  snapBmd.draw(fp);
  snap_mc = this.createEmptyMovieClip("snap_mc", 1);
  snap_mc.attachBitmap(snapBmd,0,"auto",true);
}
function stopLoading():Void {
  fp.contentPath = flvDummy;
  fp._visible = false;
  fp._x = -2000;
  fp._y = -2000;
}
function init():Void {
  fp.addEventListener("ready",Delegate.create(this, onFlvReady));
  fp.addEventListener("progress",Delegate.create(this, onFlvProgress));
  fp.volume = 0;
  fp.autoPlay = false;
  fp.contentPath = flvMovie;
}
init();
[...]
Published on Tue, 06 Mar 2007 05:45

Swappable Flex Skins

Juan Sanches at scalenine.com has posted some sweet Flex skins that look like OSX, iTunes, Windows XP, or Vista…Even cooler you can swap them at runtime.

[…]

Published on Tue, 30 Jan 2007 06:29

FuseIDE Extension

http://play.visualcondition.com/fuse/

Tween sequencing for dummies![…]

Published on Fri, 19 Jan 2007 00:23