Straighten quotes in textmate
One thing I missed from BBedit was straightening quotes. Just found these great commands that do the same thing.
One thing I missed from BBedit was straightening quotes. Just found these great commands that do the same thing.
Doing some work with Flickr’s API and Actionscript 3 today. When I finally exported my file, the Event.INIT associated with the Loader didn’t seem to be firing the way I thought it would. I was resizing an image after it had initialized, but it seemed to only work in the Flash IDE. Here’s what I started with:
private var _image:Bitmap;
public function Image (url:String):void {
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
addChild(loader);
var request:URLRequest = new URLRequest(url);
loader.load(request);
}
private function onInit (event:Event):void {
_image = Bitmap(event.target.content);
}
This code works great for loading an image on a local server or in the flash player, but my code to resize the image on init was not being run when the movie was embedded in a browser. So, I added this and figured out that it was throwing an error:
private function onInit (event:Event):void {
try{
_image = Bitmap(event.target.content);
} catch (error:SecurityError) {
trace(error);
}
}
This basically “trys” to access the content of the loader and if it can’t, throws a SecurityError (#2122). Flickr has a crossdomain.xml file that allows all access (”*”) so I was confused as to why it was throwing this error. Turns out with AS3 that you have to TELL it to check the crossdomain file. So, my new load function now looks like this:
var context:LoaderContext = new LoaderContext(true); var request:URLRequest = new URLRequest(url); loader.load(request, context);
The “true” param in LoaderContext let’s Loader know that it should checkPolicyFile. Trouble is, even after checking the policy file, I was still getting the SecurityError. Finally, with all this data in hand, I did some googling and found this. Seems that perhaps there’s some kind of redirect on the asset we are accessing, so we need to continue to hit the url with the policy file to get a valid asset. Here’s what the final init function looks like (in general):
private function onInit (event:Event):void {
if (event.target.childAllowsParent == false) {
load(event.target.url);
} else {
_image = Bitmap(event.target.content);
dispatchEvent(new Event(Event.INIT));
}
}
I had thought it was another Event.INIT firing problem but it turns out it was a sandbox violation.
I’m pretty sure that making custom components in AS3 is worthless now. It was already kinda shaky in flash 8 and the documentation lacking. Check out this example of where I’m running up against a wall:
package {
//imports
import flash.display.*;
import flash.events.*;
//class
public class Module extends Sprite {
//component property
[Inspectable] public var label:String;
//constructor
public function Module() {
trace(label);
addEventListener(MouseEvent.ON_CLICK, clicked);
}
//click event
private function clicked(e:MouseEvent) {
trace(label);
}
}
}
In this example, you create a simple sprite (the shape of which isn’t set here) that has a label property that you should be able to edit in the authoring environment. After adding it as a component in the library and editing the “label” field in the component inspector, publish. The first trace, in the constructor, will output null. It’s not set yet. But once you click on it you see the label you’ve given it. So, it is storing the input from the component inspector. However, flash AS3 doesn’t seem to provide a “creationComplete” event like Flex does. So you can’t tell at what point your properties were set.
I’m doing some work with flash.ui.Keyboard today. During testing in the Flash environment, every time I pressed (for example) the ‘F’ key, it was shifting focus to the Tools ‘Fill Transform’ tool and therefore not registering the event. To get around this, I made a copy of my shortcuts and removed all the tool shortcuts. However, the Keyboard was not registering Keyboard.BACKSPACE presses and some of the other keys. After some poking around, I found this little number when previewing the SWF … Control > Disable Keyboard Shortcuts. Duh! This makes sure than the IDE is not receiving the Keyboard events during preview.
Been meaning to post this for days, just a little shot of our Buk Turkey Day party up in Sac.
Here’s some more mysql odds and ends I’ve been picking up:
I was excited when Greg told me that Gmail had added IMAP support. I tried it out the other week and have since switched back to my old ways*. I had two main problems with it:
With both of these issues, I could have “fixed” them in Mail.app if only it had better rules. I wish you could mark messages as read of apply rules to specific folders of an IMAP account or make combinations of AND and OR. Anyway, no Gmail IMAP for me yet.
*My “old way” is to have gmail forward all mail to a AOL free webmail account I setup for this purpose. They run IMAP as well. Then I have mail.app check the AOL mail, but use the Gmail SMTP for sending. Works pretty good. One note if you want to set this up yourself: it seems to me that AOL mail accounts you setup on their own only keep like 500 messages. But if you create an AIM account and then use it’s mail, there appears to be no restrictions. This is a theory I’ve formed based on my own experience, haven’t seen anything official about it.