Friday, May 21, 2010

AS 3.0 : Google clickTag

Do you need a Google ClickTag that's coded in AS3? Then grab and bite the following Nyum-nyum codes:


YourBtnName.addEventListener(MouseEvent.MOUSE_UP,ClickThru);

function ClickThru(e:MouseEvent):void {

if (root.loaderInfo.parameters.clickTAG.substr(0,5)=="http:") {

navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG),"_blank");

}

}



Courtesy of David Stiller, Co-author, Foundation Flash CS3 for Designers

Thursday, April 8, 2010

AS 3.0 : Primer on Global To Local

Today's Nyum-nyum codes will give you a head start with:

Constraining your object/mouse as a slider
You may copy and paste the following into the first frame of your timeline.

//1. import this flash class at the very top...
import flash.geom.Point;

//2. Define a 'constraining' area...I'm making a vertical slider, hence the following coordinates
var myVerRect:Rectangle=new Rectangle(50,200,1,200);

//3. Tell Flash to find the relative distance between your dragged object, in this case a slider handle and the point of origin

MyTextField.text=nameOfClipBeingDragged.globalToLocal(new Point(specifyXPOS,specifyYPOS)).y


//4. Start Drag Action
nameOfClipBeingDragged.addEventListener(MouseEvent.MOUSE_DOWN,Drag);
function Drag(myEvent:MouseEvent):void {
myEvent.target.startDrag(true,myVerRect);
trace(MyTextField.text);
}


Wednesday, February 3, 2010

CSS: Non-image rounded corners

Not widely supported by versions of I.E. Otherwise, renders reliably in Safari and Firefox. Use at your own peril... include this snippet in your stylesheet. Then wrap your content with a DIV tag with the following ID like so div id="inner"
#inner {
-moz-border-radius: 15px 15px 15px 15px;
-webkit-border-radius: 20px; }
Click here to see example>>

Saturday, January 16, 2010

AS 3.0 : Quick + Easy BLUR script

After an exhaustive and futile search for what ought to be an easy method to a common task, I turned reluctantly to Adobe Livedoc* and extracted the necessary syntax from its unnecessarily dense documentation. I present to you a timeline-based method of scripting a 'Blur Effect'.

//1. You'll need these import statements at the very top of the actionscript panel of the 1st frame of the Main timeline.
import flash.display.Sprite;
import flash.filters.BitmapFilter;
import flash.filters.BitmapFilterQuality;
import flash.filters.BlurFilter;

/*Next I create a reusable function that accepts three parameters: The name of your Clip, How much to Blur the X, How much to Blur the Y*/

function BlurIt(ClipName,BlurXValue,BlurYValue) {
var blurX:Number=BlurXValue;
var blurY:Number=BlurYValue;

//Next Line -> Essence of the Blur Method:
var myBlur:BlurFilter= new BlurFilter;(blurX,blurY,BitmapFilterQuality.HIGH);
//attach the method to the Object (your movieclip)..
ClipName.filters=[myBlur];
}
//3. Blur Function ready for use.
BlurIt(ClipName,BlurX,BlurY);

//Example :

BlurIt(myNwee,20,20);

If you're copying the codes, you may exclude the '//' comments.

Tuesday, December 1, 2009

AS 3.0 How to load and Read External XML

/*____________________________________
RC2 XML URL Reader
______________________________________*/
//load external XML source
var loader:URLLoader=new URLLoader();
loader.load(new URLRequest("URLs.xml"));
//
/*Define a local XML Object
*/
var xmlURL:XML=new XML();
var i:Number=0;
//________________________________ target XML on successLoad
loader.addEventListener(Event.COMPLETE, ParseXML);
function ParseXML(e:Event):void {
//specify the XML Object's Event action
xmlURL=new XML(e.target.data);
/*_____________________________________
IMAGE LOADER
_______________________________________*/
function X(ClipName,i) {
var Location=xmlURL.cover.imageURL.text()[i];//fancy targets the XML node
var myRequest:URLRequest=new URLRequest(Location);
var myLoader:Loader=new Loader();
//
myLoader.load(myRequest);
//Sprite Container
ClipName.addChild(myLoader);

}
//
X(ClipLoaderOne,0);
X(ClipLoaderTwo,1);
X(ClipLoaderThree,2);
X(ClipLoaderFour,3);
X(ClipLoaderFive,4);
/////////////////////////////////////////// Click Action

Clicker.addEventListener(MouseEvent.CLICK,launchURL);
function launchURL(e:MouseEvent):void {
navigateToURL(new URLRequest(xmlURL.child(i)), "_self");
trace(xmlURL.cover.clickURL.text()[i]);
}
//
}
//


Saturday, November 14, 2009

AS3.0 Create Bitmapdata/Bitmap

Follow this link for a concise and easy-to-follow tutorial on creating Bitmapdata and how to attach a Bitmap from the Library at runtime.
http://www.communitymx.com/content/article.cfm?page=4&cid=60D13

Wednesday, April 1, 2009

Flash Liquid Layout

I have updated the 'Liquid Layout' recipe from Tutorio to AS3. 

Step 1. Ensure the HTML publishing setting in your Flash IDE at 100% height and 100% width. Align at top left.

Step 2. Copy and paste the following into the 1st Frame of the timeline. Make adjustments where necessary:


stage.addEventListener(Event.RESIZE, repositionElements)
//
function repositionElements(myevent:Event):void{
trace(stage.stageWidth);
trace(stage.stageHeight);
//'Box' being your movieclip or artwork
Box.y=stage.stageHeight-40;
}