Often, when projects become bigger and more complicated, it often is necessary gto let the application behave different when exported within the IDE and the actual LIVE project. I use this snippet, right at the beginning of my baseclass, to define in which environment the flash client is running:
Actionscript:
-
if(stage.loaderInfo.url.indexOf("file:") != -1){
-
_configXmlPath = "config.xml";
-
trace("local file");
-
}else {
-
trace("Server");
-
domain = URLUtils.getDomain( stage.loaderInfo.url);
-
}
I hope this is seflexpainatory.
Or you could just randomize the “hue” color parameter which is handily a 0-360 scale in TweenFilterLite:
theHue = (Math.round(Math.random() * 360)) ;
TweenFilterLite.to(my_mc, 2, {colorMatrixFilter:{amount:1, hue:theHue}});
ActionScript 3: Using URLLoader to send and load server variables « Tushar Wadekar
here is the most accurate description on how to send vars to a server script from flash, without opening anew browser window
In AS3 only, you can now abort a loading operation, before it has completed.
Senocular has written a post about it here.
in summary:
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("image.jpg");
loader.load(request);
addChild(loader);
// abort loading if not done in 3 seconds
var abortID:uint = setTimeout(abortLoader, 3000);
// abort the abort when loaded
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, abortAbort);
function abortLoader(){
try {
loader.close();
}catch(error:Error) {}
}
function abortAbort(event:Event){
clearTimeout(abortID);
}
Nasty Yellow Highlight on Buttons When “Tabbing”When you’re in a flash movie and you hit the “tab” button to go from button to button flash likes to put a bright bold yellow highlight around the button that is awfully ugly and annoying. This is how you get rid of that awful yellow highlight that flash produces by default.
movieClipName.tabEnabled = false;
Note: this code will also make the button not “tabbable”. Now when you hit the tab button on the keyboard it will ignore that button all together. You can still utilize it with ‘getfoucus’.
if you have nested moveclips then use this code too:
parentMovieClipName.tabChildren = false;
No more nasty default yellow highlights around anything that is tabbable in your flash movies.
Nasty Yellow Highlight on Buttons When “Tabbing” « Gena’s Blurb
Tweensy, developed by the notorious "Lost in Actionscript" blog owner Shane McCartney. I am personally a fan of Greensock's Tweenlite package, and there aren't any AS3 projects I haven't used it, but I must say Tweeny is the first one that actually woke my attention. It seems slick, fast, (very fast), and best of all are the effect packages it can be extended with. I also tried out the abilities to tween along complicated motion guides, and must say, I was really waiting for that one!
I will keep a few of my experiments with it posted here, but hey, flash community, there is movement!!
http://www.lostinactionscript.com/blog/index.php/2009/01/05/tweensy-goes-public/
Here a small collection of my favourite discoveries of flash sites.
quick recollection of best practices when loading an image (or any asset) into a flash movie from an external location.
Actionscript:
-
import flash.display.Loader;
-
import flash.display.MovieClip;
-
import flash.events.Event;
-
import flash.events.IOErrorEvent;
-
import flash.net.URLRequest;
-
-
private function ldImage(imagePath:String) {
-
throwAlert("loading " + imagePath);
-
var _loader:Loader = new Loader();
-
_loader.contentLoaderInfo.addEventListener(Event.INIT, onLdInit);
-
_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR , onLdError);
-
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLdComplete);
-
var urequest:URLRequest = new URLRequest(imagePath);
-
_loader.load(urequest);
-
addChild(_loader);
-
}
-
private function onLdError(e:Event) {
-
trace(this+" !!! onLoad ERROR !!!\n"+e);
-
}
-
private function onLdInit(e:Event) {
-
trace(e + " onLod Init");
-
}
-
private function onLdComplete(e:Event) {
-
trace(e + " onLdComplete");
-
}
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:
-
<script type="text/javascript" src="js/swfobject.js"></script>
-
-
//vars and parameters for embedded swf
-
var flashvars = { };
-
var params = { menu: "false", allowScriptAccess:"sameDomain", allowfullscreen :"true"};
-
var attributes = { id: "main", name: "main" };
-
swfobject.embedSWF("flash/main.swf", "mainFlash", "100%", "100%", "9.0.0","expressInstall.swf", flashvars, params, attributes);
-
</script>
-
-
<!--
-
html, body, #mainFlash{ height:100%; width:100%;}
-
body { margin:0; padding:0; overflow:hidden; background-color:#A31724; text-align:center; }
-
-->
-
</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:
-
stage.scaleMode = StageScaleMode.NO_SCALE;
-
stage.align = StageAlign.TOP_LEFT;
-
-
stage.addEventListener(Event.RESIZE, resizeHandler);
-
-
function resizeHandler(event:Event):void {
-
trace(stage.stageWidth + " x " + stage.stageHeight);
-
// center stuff
-
}
Recent Comments