April 14th, 2008
Although TextMate comes with a built in CSS validation command it would sometimes fail for me depending on where I was working from (some locations have proxy software on the main router). I rewrote the command in the style of the PHP-HTML validator I posted earlier. You can add more validation options using -F. I’ve only used this script on CSS only files, it might not work on inline CSS in HTML documents.
#!/usr/bin/env ruby -wKU
scope = STDIN.read
scope.gsub!(/< \/?style.*?>/, ”)
open(‘|curl -sF file=@-\;type=text/css -F lang=en http://jigsaw.w3.org/css-validator/validator’, ‘r+’) do |io|
io < < scope
io.close_write
while io.gets
$_.gsub!(/<\/title>/, ‘\&<base href="http://jigsaw.w3.org/css-validator/">’)
print $_
end
end
Posted in General | No Comments »
March 27th, 2008
It is impossible to validate local PHP files via the built in W3C validation that the TextMate HTML bundle provides because it does not parse the PHP code in the PHP document. I’ve modified the default validation script to retrieve the file using OS X’s built in apache server (the script assumes you have your files in the ~/Sites directory) so it will work for not only PHP, but any apache-interpreted language. I’ve added the ss option to the W3C validator, you can add/remove any validation options to the curl command as you see fit.
#!/usr/bin/env ruby -wKU
STDOUT.sync = true
page = `echo $TM_FILEPATH | sed “s|.*/$USER/Sites/|http://localhost/~$USER/|” | xargs curl -s`
open(‘|curl -sF uploaded_file=@-\;type=text/html -F ss=1 http://validator.w3.org/check’, ‘r+’) do |io|
io < < page; io.close_write
while io.gets
$_.gsub!(/<\/title>/, ‘\&<base href="http://validator.w3.org/">’)
puts $_
end
end
Hope everyone had a blessed and happy easter!
Posted in General | No Comments »
July 28th, 2007
I’ve seen some pretty horrible code in my days of coding, but nothing beats this:
_global.
checkEmail =
function(e) {
function checkChars
(s, i, l
) {
while (i < l &&
“_-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789″.
indexOf(s.
charAt(i
)) != -
1)
{
i = ++i;
} // end while
return (i
);
}
function checkFirstLevelDomainChars(s, i, l)
{
while (i < l && “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”.indexOf(s.charAt(j)) != -1)
{
i = ++i;
} // end while
return (i == l);
} // End of the function
var _loc1;
var j;
var _loc2 = e.length;
var _loc4 = false;
_loc1 = checkChars(e, 0, _loc2);
if (checkChars(e, 0, _loc2) == 0)
{
return (-1);
} // end if
j = _loc1;
while (_loc1 < _loc2 && e.charAt(_loc1) == “.”)
{
++_loc1;
if ((j = checkChars(e, _loc1, _loc2)) == _loc1)
{
return (-2);
} // end if
_loc1 = j;
} // end while
if (e.charAt(_loc1) != “@”)
{
return (-3);
} // end if
do
{
_loc1 = j + 1;
j = checkChars(e, _loc1, _loc2);
if (j == _loc1)
{
return (-4);
}
else if (j == e.length)
{
j = j - _loc1;
if (_loc4 && j >= 2 && checkFirstLevelDomainChars(e, _loc1, _loc2))
{
return (1);
}
else
{
return (-5);
} // end else if
} // end else if
_loc4 = e.charAt(j) == “.”;
} while (_loc1 < _loc2 && _loc4)
return (-6);
};
I’m really not sure what that programmer what smoking when he created that mess; and I really don’t want to know. It felt really good removing 65 lines of code and replacing it with this though:
_global.checkEmail = function(email) { return email.length != 0 && email.indexOf(“@”) != -1 && email.indexOf(“.”) != -1; }
Posted in Software | 3 Comments »
June 6th, 2007
In most of my flash projects I have a prototype file I include into the project. It contains additions to core objects such as Object, MovieClip, etc. Well, today I found out that some Macromedia components (ComboBox was the one I was having trouble with) don’t like additional methods to be defined on certain classes (Object was the one I found that ComboBox was having issues with); they fail to continue to work with additional methods defined.
However, there is a workaround: ASSetPropFlags. Simply hide all additional methods with this line of code:
ASSetPropFlags(Object.prototype, null, 1);
I can’t wait until AS3 can be used all the time.
Posted in Flash | 1 Comment »
May 29th, 2007
I’ve always wanted to attach a movieclip to the stage with a class other than MovieClip without having to use swfmill or the ide to create a movieclip with linkageID + custom class. Well that day is finally here! I found a nice snippet of code on the net and modified it a bit to act more like attachMovie (ability to specify an initOb). The result? createClassMovieClip:s
/*
Description: A function used for creating empty movie clips with subclass association.
Parameters:
c:Function - The class to associate with the the empty movie clip.
name:String - The instance name for the empty movie clip.
depth:Number - The depth for the empty movie clip.
initOb:Object - Optional, object to copy properties from
Returns:
MovieClip - A reference to the newly created movie clip.
*/
MovieClip.prototype.createClassMovieClip = function(c:Function, name:String, depth:Number, initOb:Object) : MovieClip {
var mc:MovieClip = this.createEmptyMovieClip(name, depth);
mc.__proto__ = c.prototype;
mc.constructor = c;
if(initOb) {
for(var prop in initOb) {
mc[prop] = initOb[prop];
}
}
c.call(mc);
return mc;
}
Use it just like attachMovie except you specify a class for the first parameter, eg:
createClassMovieClip(CustomClass, “new_clip”, getNextHighestDepth(), {_x:10, _y:10, something:function(){this.something = 10;}})
Pretty slick!
Snipplr
Snipplr is a neat site I came across a couple months ago but forgot to post about. It a nicely designed web-2.0-ish site that allows you to post and view code snippets for various different languages (Cocoa, PHP, HTML, CSS, etc). It even has cloudtags and TextMate integration! I’ve been posting some smaller snippets on that site instead of the source code page, so go and check it out.
In the same vein, Code Beach was recently launched. Code Beach is basically the same idea as Snipplr, except it is focused solely on Cocoa based code snippets. It’s nice to see more of these code sharing sites cropping up, they save alot of time!
Posted in General | No Comments »
May 9th, 2007
I’ve written about the pains of fonts in flash before; and it something that still plauges my work today. However, since that post new tools have been created, new workflows introduced, and with that some new findings.
Fonts With SWFMILL
SWFMILL is an awesome tool that may allow you to leave the Flash IDE untouched for some projects. However, embedding fonts seems to be scarcely documented (I had trouble getting the methods documented working). Here are the two links I’ve found that document embedding fonts with swmill:
I wasn’t able to get embedded fonts working using the information above, so here is my method. This is what my swfmill xml looks like.
FontFile.ttf must be referenced relative to the location of the swfml file, and must be a TrueType font for swfmill to read it successfully. If you want to use a non-TrueType font convert it to a TrueType font with a tool such as FontForge (works great and its free, but has a horrific UI).Now if you create a NavButton class that looks something like this:
class NavButton
extends MovieClip {
private var oTitle:
TextField;
function NavButton() {
super();
oTitle.selectable = false;
oTitle.multiline = false;
oTitle.wordWrap = false;
oTitle.textColor = 0xFFFFFF;
oTitle.autoSize = true;
oTitle.text = “This is a title”;
}
}
And attach the NavButton to the stage using attachMovie() you should see the text come up. Note: you don’t need to set oTitle.embedFonts = true; to make this work correctly! Actually, dont use embedFonts at all!
You may have noticed the properties that I had to set on oTitle, this will be different for every situation. It seems that swfmill sets a bunch of default properties when creating a textfield. As a reference, here is the output from dumpObject(oTitle) (dumpObject() is a method from my debug class):
styleSheet:undefined
mouseWheelEnabled:true
condenseWhite:false
restrict:null
textHeight:48
textWidth:54
bottomScroll:1
length:12
selectable:true
multiline:true
password:false
wordWrap:true
background:false
border:false
html:false
embedFonts:true
maxChars:null
maxhscroll:0
hscroll:0
variable:null
htmlText:hello world!
type:input
text:hello world!
autoSize:none
tabIndex:undefined
textColor:0
backgroundColor:16777215
borderColor:0
maxscroll:2
scroll:1
filters:undefined
sharpness:undefined
thickness:undefined
antiAliasType:undefined
gridFitType:undefined
Shared Fonts in Flash IDE
Shared fonts, especially shared pixel fonts, are tricky business in the Flash IDE. Sometimes I wonder if it’s worth the effort, and whether I should just embed the fonts in each SWF. Alot of times I get blurred text when loading the pixel font from a shared library, but no blurring if the font is embedding in the swf itself. Shared fonts seem to work well with non-pixel fonts though; so if you dont need pixel fonts I would definitly use shared libraries. If you are looking at using shared fonts in your project I would recommend checking out Shared Fonts Manager.
Posted in Flash | No Comments »