Loader.close(), a slippery little basted!
Posted on June 23, 2008 by Jörgen
Filed Under AS3, Flash Tips | Comments Off
I was working with the Loader class and thought that a good practice to avoid a lot of unnecessary bandwidth loadings is to clear any loading progress before I start a new one.
The method to use in the Loader class is the close() function. And the BIG problem in this is that when I tried in the flash ide the loader didn’t stop the stream… I tried everything… cleared every event listener, but in the flash “bandwidth profiler” I could see that the swf where still loading… so when I clicked at the navigation buttons as a maniac the “bandwidth profiler” showed me a bunch of loading swf simultaneously. After a lot of tryes end error I found out the the only problem is the falsh ide and the “bandwidth profiler”. If I do the same on a web server the connection cuts of the I get a sweet “Client closed connection before receiving entire response”. So much headache for nothing…
Thank god for Charels! The best debugging tool ever! if you don’t got it, go and get it here»!
New Flash Player new issues…
Posted on June 12, 2008 by Jörgen
Filed Under AS3, Flash Tips, General | Leave a Comment
In the new Flash Player 9,0,124,0 there is a lot of new security changes…
If you are (like me) used webService and the server is in a other domain then you will get a sweet secure error:
Server Error: [RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]
What I did was adding this line in the crossdimain.xml file and the error went away!
<allow-http-request-headers-from domain=”*” headers=”*”/>
So here is the complete crossdomain file:
<cross-domain-policy>
<allow-http-request-headers-from domain=”*” headers=”*”/>
<allow-access-from domain=”*” />
</cross-domain-policy>
If you are usingSocket connection in flash the problem is not this easy to fix. Read this article about the new socket security rules:
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
Here you can read about the new security rules for flash player 9,0,124,0
http://www.adobe.com/devnet/flashplayer/articles/flash_player9_security_update.html
Basic Flash-tips #3: Improve your Align skills
Posted on April 17, 2008 by inEar
Filed Under Flash Tips | Leave a Comment
Here are some very useful shortcuts to position things faster on stage (PC):
Turn on/off scale “To stage”: ctrl+alt+8
Horizontal align: ctr+alt+(1-3)
Vertical align: ctr+alt+(4-6)
And another feature in the align toolbar is “Match size” wich I never used until recently. Useful when resize a background-shape to stage size.
And the shortcuts for that with “To Stage” on:
ctrl+alt+shift+7 –> ctrl+alt+shift+9
Basic Flash-tips #2: Runtime-errors with row-numbers
Posted on April 17, 2008 by inEar
Filed Under Flash Tips | 1 Comment
Have you ever been missing the row-number for an error thrown at runtime in Flash CS3, for example when working with loaded content such as XML? Just activate “permit debugging” in Publish settings and there it is.
Basic Flash-tips #1: Potapenko Extensions
Posted on April 17, 2008 by inEar
Filed Under Flash Tips | Leave a Comment
I found this flash-extension really useful. Specially the “multi edit library” feature. Select multiple images in the library and change smoothing and compression all at once.
http://potapenko.com/eng/extensions.htm
TextField gets cut
Posted on April 14, 2008 by Dave
Filed Under Flash Tips, Font related | Leave a Comment
Annoying inssue with a centered textfield paragrah randomly get’s cut off at the right end.
Only solution for now seems to be to keep the the textfield paragraph left aligned and then center the textfield it self by measuring width and position.
The smallest things can take the longest time
Posted on April 10, 2008 by Dave
Filed Under AS3, Flash Tips | Leave a Comment
Recently pulled my hair over something that probably is quite logical.
To get around crossdomain issues I placed a shell-swf on a remote server that in turn loads the main-swf. Have done it like that a thousand times before but this time I just couldn’t get it to work.
It turns out that i tried to set stage.scaleMode in the main.swf which of course isn’t allowed to write that property. Only the shell has that privelige. So the swf just failed silently and it took wuite some time to figure out the problem.
Resolution of textures
Posted on April 9, 2008 by Dave
Filed Under 3D Studio Max | 1 Comment
It’s probably due to my lack of understanding of the program and it’s principles, but how do you get it to use bitmap textures with a higher resolution? It seems as if you can’t have larger images than about 4000 pixels in height without it generating memory error, but maybe that is just my system that is inadequate.
Solved it for now by splitting the texure (for my globe) into smaller images.
Mouse-position outside flash tutorial
Posted on March 17, 2008 by inEar
Filed Under Flash Hacks, Flash Tips | Leave a Comment
To use javascript with banners can be a true headache. I wan’t to share my exerience of the obstacles I found so far.
Before you start, make sure you have the permission to use javascript on the sites. Sometimes you can sneak in your javascript in the embed-code generated by the media agencies, the siteowner does’nt even have to know about it. But sometimes, when you need to fire some code on the onInit-event, you have to get access to the document header. However, with some workarounds you don’t really need that. In the following example you can put the script after the swfobject-embedding.
nbsp;
Javascript source:
var mouseY = 0;
var bannerX = 0;
var bannerY = 0;
document.onmousemove = updateMousePos;
function updateMousePos(e) {
if( !e ) {
if( window.event ) {
//IE
e = window.event;
}
else {
//Fails
return;
}
}
if( typeof( e.pageX ) == 'number' ) {
//most browsers
var xcoord = e.pageX;
var ycoord = e.pageY;
}
else if( typeof( e.clientX ) == 'number' ) {
//Internet Explorer and older browsers
//other browsers provide this, but follow the pageX/Y branch
var xcoord = e.clientX;
var ycoord = e.clientY;
var badOldBrowser = ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || ( navigator.vendor == 'KDE' );
if( !badOldBrowser ) {
if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//IE 4, 5 & 6 (in non-standards compliant mode)
xcoord += document.body.scrollLeft;
ycoord += document.body.scrollTop;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//IE 6 (in standards compliant mode)
xcoord += document.documentElement.scrollLeft;
ycoord += document.documentElement.scrollTop;
}
}
} else {
///Fails
}
mouseX = xcoord
mouseY = ycoord
}
//called from flash
function getParameters() {
//if not bannerpos is set, try to get it
if( bannerX == 0 && bannerY == 0) {
getBannerPos()
}
if( (bannerX == 0 && bannerY == 0) || (mouseX == 0 && mouseY == 0)) {
return "error"
}
else
return bannerX+":"+bannerY+":"+mouseX+":"+mouseY ;
}
function getBannerPos() {
var flashMovie = document.getElementById("projectorBanner");
if( flashMovie ) {
if( flashMovie.offsetParent ) flashMovie = flashMovie.offsetParent
if (flashMovie.offsetParent && flashMovie.tagName.toLowerCase() != 'body') {
do {
bannerX += flashMovie.offsetLeft;
bannerY += flashMovie.offsetTop;
} while (flashMovie = flashMovie.offsetParent);
}
}
}
Okey, we gonna follow the mouse, so here we go…
Begin by adding the onmousemove-event. This event is firing quite fast, so you don’t want to send data to the flash every time. Instead I pull the data from inside the flash via ExternalInterface.call().
The key to follow the mouse is to know where the banners top-left-position is. There aint no crossbrowser-property for this, so you recursive checks the positions via offsetTop and offsetLeft to the parent element. See getBannerPos-function. I noticed that firefox added the same offsetHeight twice for the embed-tag and the parentElement. This row fixed the problem:
if( flashMovie.offsetParent ) flashMovie = flashMovie.offsetParent
It’s a safe fix, because the offset to the object/embed-parent is zero in all other cases. We only need to check the position once. So we keep checking until we get a result. The onmousemove-event may be fired many times before the position can be measured. So while bannerX/bannerY is 0, keep checking. Be careful with Explorer, if we check the position to soon, we can get the left position before the top position is available (especially with floating css-divs), so wait for both parameters to be non-zero. Put the “getBannerPos()” in the method called from flash, and your home safe.
Next thing is to get the scroll position. Because this changes over time, I do that every time onmousemove fires. To get the scrollposition is a little more tricky due to all browsers different implemention, I just used a script I found at google.
So now we got the four variables with what we needed. MouseX, mouseY, bannerX, bannerY. Time for flash to do some magic.
actionscript source:
if( bMouseOver ) {
//internal position
bannerX = 0;
bannerY = 0;
//relative to browser
browserMouseX = this._xmouse + bannerX
browserMouseY = this._ymouse + bannerY
}
else {
//get from Javascript
var strParameters = ExternalInterface.call("getParameters");
arrPositions = strParameters.split(":");
if( strParameters != "error" && strParameters != undefined) {
bannerX = Number(arrPositions[0]);
bannerY = Number(arrPositions[1]);
browserMouseX = Number(arrPositions[2]);
browserMouseY = Number(arrPositions[3]);
}
}
//do what ever you want with it
updatePositions( bannerX,bannerY,browserMouseX,browserMouseY);
In order to have a smooth gap when rolling over and out the banner you have to setup a mouse-listener here as well. Otherwise, it will get jumpy or not working at all. Some browsers don’t fire mousemove-events when over a flash. There is a known problem to register a mouse leave from the stage. I checks if the mouseX and mouseY changes. If not, wait a few frames and then assume we don’t have the users attention anymore. This can certainly be made better by checking mouse position in javascript, but this worked good enough this time. So, when the flash mouse-position stops, we will listen to the javascript-position.
What to do with the knowledge of mouseposition is up to you. In my example I render a paralax-effect based on the values.
3D effect with filters
Posted on March 14, 2008 by inEar
Filed Under Flash Tips | Leave a Comment
By mixing multiple layers of filtereffects you can make this nice little 3d-effect.
Flashcontent
Here is the recepy:
Create these filters:
var filter1 = new flash.filters.DropShadowFilter();
filter1.angle = 90;
filter1.distance = 1;
filter1.blurX = 0;
filter1.blurY = 0;
filter1.color = 0xf3d22f
filter1.strength = 1;
var filter2 = new flash.filters.DropShadowFilter();
filter2.angle = 90;
filter2.distance = 2;
filter2.blurX = 10;
filter2.blurY = 10;
filter2.color = 0×000000
filter2.strength = 0.5;
var bevelFilter = new BevelFilter(2,90,0xfedc74,10,0×929292,10,2,2,0.42);
Add “filter1″ 12 times or what you prefer (myMC.filters[filter1,filter1,...]).
Add a regular drop shadow ( “filter2″) at the end.
In this example a have added a beveleffect (”bevelFilter”) to each slice. To get the correct z-rendering of the blue slice I scripted a mask, based on the angle of that slice.
The downside is the lack of antialiasing on the edges.
« Previous Entries