[AS2] Fullscreen, Scaled Fullscreen (zoom)

27 05 2008

AS2 Normal fullscreen:

//Rectangle is needed when using hardware scaling.
import flash.geom.Rectangle;
// functions to enter and leave full-screen mode
function goFullScreen()
{
Stage["displayState"] = "fullScreen";
}
function exitFullScreen()
{
Stage["displayState"] = "normal";
}
// function to enable, disable context menu items, based on which mode we are in.
function menuHandler(obj, menuObj)
{
if (Stage["displayState"] == "normal")
{
// if we're in normal mode, enable the 'go full screen' item, disable the 'exit' item
menuObj.customItems[0].enabled = true;
menuObj.customItems[1].enabled = false;
}
else
{
// if we're in full screen mode, disable the 'go full screen' item, enable the 'exit' item
menuObj.customItems[0].enabled = false;
menuObj.customItems[1].enabled = true;
}
}
// create a new context menu
var fullscreenCM:ContextMenu = new ContextMenu(menuHandler);
// hide the regular built-in items
fullscreenCM.hideBuiltInItems();
// now, add the items to enter and leave full screen mode
var fs:ContextMenuItem = new ContextMenuItem("Go Full Screen", goFullScreen);
fullscreenCM.customItems.push( fs );
var xfs:ContextMenuItem = new ContextMenuItem("Exit Full Screen", exitFullScreen);
fullscreenCM.customItems.push( xfs );
// now, attach the context menu to any movieclip in your movie.
// here we attach it to _root, (even though using _root is generally a bad idea,)
// so it will appear if you right click anywhere on the movie.
_root.menu = fullscreenCM;


AS2 Zoom Fullscreen

// An alternate full screen function that uses hardware scaling to display the upper left corner of the stage in full screen.
function goScaledFullScreen(){
trace ("HO")
var screenRectangle:Rectangle = new Rectangle();
screenRectangle.x = 0;
screenRectangle.y = 0;// zoom on 0;0

screenRectangle.width=Stage.width/2;
screenRectangle.height=Stage.height/2;
Stage["fullScreenSourceRect"] = screenRectangle;
Stage["displayState"] = "fullScreen";
}





CSS: tooltips

4 05 2008

First of all, let’s create the CSS content:

CSS code

a{
	z-index:10;
	}
a:hover{
	position:relative;
	z-index:100;
	}
a span{
	display:none;
	}
a:hover span{
	display:block;
	position:absolute;
	float:left;
	white-space:nowrap;
	top:-2.2em;
	left:.5em;
	background:#fffcd1;
	border:1px solid #444;
	color:#444;
	padding:1px 5px;
	z-index:10;
	}

And the Html:

Html code

<a href="#">Title <span>Tooltip</span></a>





[snackshot] Loading an external image

3 05 2008

snackshotz

Actionscript 3 code

var imageLoader:Loader = new Loader();
var image:URLRequest = new URLRequest("http://server.com/folder/file.png");
imageLoader.load(image);
addChild (imageLoader);
imageLoader.x = 200;// AS2 reference: _x
imageLoader.y = 300;// AS2 reference: _y





Loading XML

3 05 2008

XML

ActionScript 3 uses a system called ECMAScript for XML (E4X).

In AS2 we were used to create an XML object and then we called the XML.load() method in order to load in an external file. In AS3 loading of external XML files is handled by the new URLLoader class.

So, let’s create a new instance of that class:

Actionscript 3 code

var loader:URLLoader=new URLLoader;

After that we need to create an event to launch the function when the XML is loaded. The event must be deleted before deleting the object, otherwise it will sucks CPU

Actionscript 3 code

loader.addEventListener(Event.COMPLETE, loadXML);

Let’s give the loader the target XML to load:

Actionscript 3 code

loader.load(new URLRequest("content.xml"));

Finally, let’s create the function to load the content using the Event.target.data property:

Actionscript 3 code

function loadXML(e:Event):void
{
xml = new XML(e.target.data);
trace(xml);
}