By jberman on June 24, 2009 at 4:43 pm.
Filed under: Browsers, FireFox, HTML, IE, Safari
When editing several files for a French web site that contained non-ASCII latin characters I noticed some strange rendering inconsistencies between Safari and Firefox / IE.
Safari was displaying the characters correctly, however Firefox/IE were not. I tried resaving the file in all different encodings from UTF-8, UTF-16, to Western ISO Latin and got very weird results.
Then I noticed a tag that had been in the existing version of the site:
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
Even though my file was saved as UTF-8, this tag was confusing Firefox and IE into rendering my character data incorrectly. Interestingly, Safari was able to look at the actual file encoding and ignore this meta information.
To fix it all it took was making sure the file was saved as UTF-8 and then making sure the meta tag reflected this:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
If you encounter strange character rendering then give this a try!
By jberman on June 12, 2009 at 3:36 pm.
Filed under: HTML, Javascript
Here’s a quick and easy way to open a pop up window that will gracefully degrade to just showing the link in the same window if the user has pop-ups disabled. The “windwidth” and “winheight” params can be changed. This will also center the window on the screen and bring it the the foreground. I’d use this way of opening pop-up windows whenever possible.
By jberman on June 3, 2009 at 9:30 am.
Filed under: Actionscript
I searched forever on trying to find a good way to preload an external SWF in AS3 while passing through external FlashVars. I finally saw this post and it worked perfectly!
http://www.zedia.net/2008/external-preloader-more-complex-cases/
The trick is writing an Interface – in this case it’s a way of having the preloader call the init function of the main document class without requiring all of the internal linked assets of the SWF. The main document class then implements the interface (shown below).
So I just wrote an Interface that has an init() method with each of my FlashVars as arguments:
MyFlashApp_Interface.as
package {
public interface MyFlashApp_Interface{
function init(externalArg1:String, externalArg2:String):void;
}
}
Then in my preloader I can import it and use it for casting. This can be done in a frame script.
MyFlashApp_loader.fla (Frame 1 Script)
import MyFlashApp_Interface;
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("MyFlashApp.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
loadBar.gotoAndStop(Math.ceil(perc*100));
}
function done(e:Event):void
{
// cast the loader content as MyFlashApp_Interface interface
var mainContent:MyFlashApp_Interface = MyFlashApp_Interface(l.content);
addChild(Sprite(mainContent) );
mainContent.init( String(root.loaderInfo.parameters.externalArg1),
String(root.loaderInfo.parameters.externalArg2) )
}
stop();
Then in my main class, I implement the interface and have some extra stuff in the constructor so it will initialize correctly when placed on the stage using addChild. Also I put in a check to prevent the init() function from being called more than once:
MyFlashApp.as
public class MyFlashApp extends Sprite implements MyFlashApp_Interface {
public var externalArg1:String="default_value";
public var externalArg2:String="default_value";
private var inited:Boolean=false;
public function MyFlashApp():void {
if(stage!=null) {
// stage will be null when this movie is loaded externally
// otherwise call the _init function
_init();
}
}
public function init(_externalArg1:String, _externalArg2:String):void{
// this function is called by the MyFlashApp_Interface interface
// when this SWF is loaded externally
if(_externalArg1!="undefined")
externalArg1=_externalArg1;
if(_externalArg2!="undefined")
externalArg2=_externalArg2;
_init();
}
// internal init function
private function _init(evt:Event=null) {
if(!inited) {
inited=true;
// initialize code goes here
}
}
}
By jberman on May 22, 2009 at 10:35 am.
Filed under: Actionscript, Languages
I couldn’t find this written anywhere so I wrote it myself.
I was storing dates in this string format: “2009-02-18 14:47:24″
And I needed to convert it to a date in Actionscript. Here is the function:
function parseDate(str:String):Date {
var d:Array = str.split("-");
var year:Number = parseInt(d[0]);
var month:Number = parseInt(d[1]);
var d2:Array = d[2].split(" ");
var day:Number = parseInt(d2[0]);
var d3:Array = d2[1].split(":");
var hour:Number = parseInt(d3[0]);
var minute:Number = parseInt(d3[1]);
var second:Number = parseInt(d3[2]);
var theDate = new Date(year, (month-1), day, hour, minute, second);
return theDate;
}