We’re using Flash to inject javascript onto our page, and to save space, we’re using a minifier to produce smaller javascript code. The issue is that we’re using a string replacement on our code and the minifier produces an odd result.
Consider the following code:
var id = myobj['ID_PLACEHOLDER'];
When we inject the code, we do a replace on ID_PLACEHOLDER and replace it with the appropriate ID. This is great, except that our minifier sees this as a waste of chars and minifies the system to:
var id = myobj.ID_PLACEHOLDER;
This would be well and good except that our IDs can begin with numbers and Javascript variables cannot. To solve this, I had to modify our placeholder to be:
var id = myobj['1_ID_PLACEHOLDER'];
This does not minify and produces correct code on the injected end.
Your externalinterface call works fine in chrome, safari, maybe even IE. That’s because it takes a second for Firefox to get with the program and actually shove your object into the element.
here’s a happy little hack to make things work again:
Flash:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("myFunction", myFunction);
function myFunction():void
{
trace("JS Callback Successful");
}
Javascript:
//the swf id is the object into which SWFobject has loaded your SWF file
var swf= document.getElementById("my_swf_id");
try {
swf.myFunction();
}
catch (e) {
//swf is not loaded yet, wait a bit and try again
setTimeout(function(){
swf.myFunction();
}, 10);
}
Just spent a minute looking for how ExternalInterface works. Here’s some handy code of how to make specific things happen in AS3:
ExternalInterface.call("alert","message");
Launches an alert window with “message” as the content.
trace(ExternalInterface.call("function(){return window.location.href;}"));
The call returns the window.location.href of the current page and is then traced to the output.
Note: This is for PHP 5.0 and higher.
I’ve seen a bunch of these out there, but I don’t see why they should be so complex. Here’s the code for the top of your page
$start_time = microtime(true);
Then, at the bottom, put this:
$load_time = microtime(true) - $start_time;
Microtime produces a number that can be used to measure milliseconds. by including true, we request a number instead of a string like “ms sec”, which isn’t what we want.
The $load_time var contains a float (number) that indicates how long the page took to load. Use this as you see fit.
April 7th, 2011 in
PHP |
No Comments
A computer science professor at Cal Poly, San Luis Obispo, came up with a law that for any given task, there is a point between procrastination and quality that provides the optimal result.
For example:
You are given an assignment that is due 2 months from now that requires 1 week of work.
Example 1, the early bird:
You begin immediately, you will finish the task with at most 8 weeks to spare.
Unfortunately, your professor then cancels the assignment 3 weeks in and you find that you’ve wasted a week of your time for nothing.
Example 2, the procrastinator:
You wait till 4 days before deadline to begin.
Your quality suffers and you get a bad grade.
Example 3, the optimal delay:
You wait 6 weeks before beginning and take extra time to do a good job.
Your teacher probably won’t cancel their plans last minute, so you’re safe.
You get a good grade and you’re sure you didn’t waste your time.
This applies well to classes, but also applies very well, I’ve found, to the real-world example of my job. I often have tasks that get re-prioritized, canceled, or changed, and this law helps me ensure I’m always on task with something worthwhile.
When you use JSFL to do something to the selection array, such as
MMExecute("fl.getDocumentDOM().selection[0].x += 50;");
If that’s all you do, saving flash then closing the file won’t keep your changes.
However, modifying objects on stage using things other than selection can provoke a change.
MMExecute("fl.getDocumentDOM().moveSelectionBy({x:0, y:0})");
Is an excellent workaround originally posted at kirupa
March 24th, 2011 in
Flash,
JSFL |
No Comments
I know what you’re thinking, “I just downloaded a new mp3 audiobook and I want to listen to it!” Well, let me tell you, I know it’s there, you know it’s there, but does the music player? No. Even stopping the service doesn’t help. What does help?
Open Settings
Go to SD card & phone storage
Unmount the SD Card
Re-mount the SD card
Re-open music
This should do it
March 11th, 2011 in
Android | tags:
mp3,
music,
phone |
2 Comments
My job is an amazing place to work. We build online advertising and much of the problems I’ve posted about here are the result of my work at Say Media. We’re using Javascript, PHP, and Actionscript to produce a fast, stable, simple UI system that couples to a backend produced by Hadoop and Hive, Perl, Python and Django. Our daily problems range from dealing with scale (billions of viewers) to usability.
As a company, we’re still growing by leaps and bounds, but have good people at the helm. I can’t think of another job I’ve enjoyed more from the technical aspects, and the people here are the best I’ve ever worked with.
Send me your resume and I’ll do my best to get you an interview.
For our list of jobs, check out http://saymedia.com/jobs.php
In a previous post, I complained about the lack of connection of dates from AS3 to PHP. This is partially due to incompatible formats, but also may have had something to do with server vs. local time.
AS3 always returns the local time of the user. PHP always returns the local time of the server. This can cause all sorts of problems when using mysql to bridge the two. The obvious solutions are to have your computers in the same time zone OR to use unix epoch time.
I’ve always used NOW() as a mysql system to add the date, but this provides local server time.
UTC_TIMESTAMP() instead provides the GMT time, which is what Unix epoch time is based upon. This should be more consistent and more easily converted.
Keep in mind, however, that storing a unix timestamp in an int field is still a bit more simple to understand, easier to sort, and just as easy to convert.
February 25th, 2011 in
PHP,
mysql |
No Comments
Here’s the concept:
In a file that’s publishing to Flash 9, create a textfield, give it an instance name of “tf1″, set the font to comic sans, and make it dynamic.
In the actionscript, do the following:
tf1.text = "this text is normal";
tf1.rotation = 30;
when you compile, you should get an error like
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
This is solved by embedding the fonts, but when you’ve got one font with multiple states, things get a little weird.
Duplicate your textfield and set the instance name to tf2
Set the font to comic sans bold
Click the Embed button. Comic Sans Bold will be added. Choose the typical settings for embedding, Upper, Lower, Numbers, Punctuation and hit ok.
Click your other textfield and hit Embed. The second font, Comic Sans Regular will be added. Choose the typical settings for embedding, Upper, Lower, Numbers, Punctuation and hit ok.
Set your actionscript to
tf1.text = "this text is normal";
tf1.rotation = 30;
tf2.text = "this text is bold";
tf2.rotation = 30;
An odd thing happens. Whichever font we embedded first seems to be the only one that’s used. This is fixed in one of two ways:
Okay way:
Use htmlText with italic and bold indicators to produce the effect you want.
tf1.text = "this text is normal";
tf1.rotation = 30;
tf2.htmlText = "<b>this text is bold</b>";
tf2.rotation = 30;
Better way:
use getTextFormat and setTextFormat
var format:TextFormat = tf1.getTextFormat();
tf1.text = "this text is normal";
tf1.setTextFormat(format);
tf1.rotation = 30;
format = tf2.getTextFormat();
tf2.text = "this text is bold";
tf2.setTextFormat(format);
tf2.rotation = 30;
this can also be done more dynamically using functions:
function setText(txt, val)
{
var format:TextFormat = txt.getTextFormat();
txt.text = val;
txt.setTextFormat(format);
}
setText(tf1, "this text is normal");
setText(tf2, "this text is bold");
tf1.rotation=30;
tf2.rotation=30;
cs5_font_embedding.fla