"as3" Category


XML and Flash : Get yourself some ForX


Monday, June 30, 2008

If there's one class that keeps me coming back to as2 it's ForX (Standing for Formulated XML) by Orion Syndrome : http://www.orionsyndrome.com/.. Ok it's not the most complete class and has it's limitations (multi dimensional XML arrays) but for dealing with simple XML driven flash applications such as galleries, news, tickers and alike it's hard to fault.

So What is ForX .. I will try and explain

  • ForX is a utility class that helps a developer or designer play with XML data in Flash ActionScript 2.0 (no as3 code as yet).
  • Can speed up your work flow, helps you speed up that time costing practice of referencing parent / child nodes
  • The code is simple, clean and works with both attributes and node data

For example ForX allows you to get data simply.. I've taken this example from the PDF manual which comes with the download.

 
/* Basic Dot Path Notation sample
Let’s make a sample XML*/
var xml:XML = new XML('<farm><backyard>
<pighouse>
<pig name="Matilda" />
<pig name="Donald" /></pighouse></backyard>
</farm>');
// We pass that XML to the newly created ForX
var forx:Forx = new Forx(xml);
// First, we try to use getPathNode() method and store that information
var pighouse:XMLNode = forx.getPathNode("farm.backyard.pighouse");
// Next, we try to get the pig node from that pighouse
var pig:XMLNode = forx.getPathNode("pig", pighouse);
// Let’s see what we get
trace(pig);
// Note the casing of the words we used in getPathNode, and it worked!
// Also note that we got only one of the two pigs
// Check the next example for how to get the other pig as well
 

Put simply Forx is a time saver, Lets just hope a as3 version is in the pipeline soon, as this is one class add on no developer designer can afford to miss out on.

If anyone else knows of any other add on for flash regarding XML then please feel free to contact me...

Musing done.

Disabling the context menu in as3..


Tuesday, March 11, 2008

Quick little code post here.. took me a while to work out how to do this, it's always the smallest things as they say.

 stage.showDefaultContextMenu=false;

You can of course customize the menu, i'm yet to experiment with that but here's a useful tute about the method, straight from drawlogic.com

Article Link

http://drawlogic.com/2007/06/12/howto-using-the-contextmenu-in-as3-with-fullscreen-mode-as-a-sample/

Simple MPU Video Player in AS3


Monday, March 3, 2008

I spent the morning looking for a way to make a simple video player in as3 for a video mpu.. all it needed was a play pause button and a mute button, after searching the web I came up with this little code, put together from a few different sources.

Hope it helps some of you out there.. ( I haven't classed it up, didn't see the need for such a small little project)

import fl.video.*;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;

// Set up the video component from the components lib name it display
//and add the source
var flvControl = display
var flvSource = "hhw_Intl_trailer_n_300k2.flv";
//Set up the sound transformer object used to control the volume.
var st:SoundTransform=new SoundTransform();

// Loop the video at end
function completeHandler(event:VideoEvent):void {
flvControl.seek(0);
flvControl.play();
playPause_btn.gotoAndPlay("play");
}
//
flvControl.addEventListener(VideoEvent.COMPLETE, completeHandler);
flvControl.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, playvideo);

function playvideo(event:VideoEvent):void{

//Opening Volume Set to Mute and Play Pause Btn set on pause
playPause_btn.gotoAndPlay(1);
// Not volume is now 0 - 1 not 0 - 100 so 50% audio would be 0.5
st.volume = 0;
flvControl.soundTransform = st;
//
mute_btn.gotoAndPlay("mute");
}

// Set the video path
flvControl.source = flvSource;

//Set Hand Vars - Puts the hand cursor back
playPause_btn.buttonMode = true;
mute_btn.buttonMode = true;
click_tag_mc.buttonMode = true;

// Add Play Pause Button code
function playHandler(event:MouseEvent):void {
if ( flvControl.playing ) {
flvControl.pause();
playPause_btn.gotoAndPlay("pause");
} else {
flvControl.play();
playPause_btn.gotoAndPlay("play");
}
}

playPause_btn.addEventListener(MouseEvent.CLICK, playHandler);
// add audio mute code
function audioHandler(event:MouseEvent):void {
if (flvControl.soundTransform.volume == 1) {
st.volume = 0;
flvControl.soundTransform = st;
mute_btn.gotoAndPlay("mute");} else {
st.volume = 1;
flvControl.soundTransform = st;
mute_btn.gotoAndPlay("unmute");	}

}

mute_btn.addEventListener(MouseEvent.CLICK, audioHandler);

//Click Tag
click_tag_mc.addEventListener(MouseEvent.CLICK,clickTag);
//Click Tag function
function clickTag(event:MouseEvent){
if(root.loaderInfo.parameters.clickTAG.substr(0,5) =="http:"){
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");
}
}
playPause_btn.gotoAndPlay(2);

Not to fancy but does the Job, some things worth noting.. the flash compliler seems to have some errors when it comes to adding the click tag var.. so you have to add it as a blank or "", well that's the only way i've found so far

If anyone would like the fla please let me know.

Update.

I've since discovered the right way to get the clickTAG into your as3 flash movie thanks to this general discussion at www.adobe.com click here to read it, i'm far to lazy to cut and paste. The Script is now updated for click Tag adserving.

technorati tags:, , , , , ,