Archive for the ‘ActionScript’ tag
Install multiple versions of Flash plugin for Firefox
As developing ActionScript projects, one have to frequently switch between different Flash versions and test. Here is a tip for Mac OSX ( also works on Windows I think ) to install multiple versions of Flash Player plugins for Firefox.
When Firefox starts, it scans for plugins in 3 sets of directories:
- General plugin directory for current system and user, e.g.
/Library/Internet Plug-Ins/ - Plugin directory for current application executable file, e.g.
/Applications/Firefox.app/Contents/MacOS/plugins/ - Plugin directory for current profile, e.g.
~/Library/Application Support/Firefox/Profiles/fw9q5h64.default/plugins
Then it will
sort by modification time
, dedupe and load all the plugins.
Now you get the trick:
- Extract the desired firefox plugin files (
e.g. Flash Player.plugin
and
flashplayer.xpt
on Mac ) from Flash plugin installer or copy from installed directory ( e.g.
/Library/Internet Plug-Ins/
on Mac ) - Copy these files to your favorite firefox app or profile directory
- use the command
touch -t 201603150101.01Flash Player.plugin
flashplayer.xpt
to make the mtime larger than the one in the general directory.
- repeat above steps for all flash versions you want.
Update: you should check “Open using Rosetta” when playing Flash 8 or earlier with Firefox on Mac.
Detect ActionScript 2/3 in TextMate
I made
a very rough tmplugin
(TM 1.x OSX 10.4+ UB) to search the word “package” in the beginning of first 20 lines of .as file to determine whether it’s AS3 or AS2, then select a proper bundle. It’s modified from
TabMate
.
You should have
ActionScript
and
ActionScript 3
tmbundle before install this tmplugin.
Cross-domain classes in ActionScript 2.0
Yes, you are right that we still live in a world with ActionScript 2.0 somewhere.
As described by
Adobe
, content loaded from different domains belong to different sandboxes, and you can make them communicate to each other by calling System.security.allowDomain(”*”).
However, this only permits you calling methods in the swf from the other domain, not the class definitions. In order to create an instance of a class from the other domain, you have to:
// http://domain1/a.swf _global["Tier"] = _root._parent.GetClassTier(); var t = new Tier();
and
// http://domain2/b.swf
class Tier {
//...
}
function GetClassTier() {
return _global.Tier;
}
Ok, now you are able to create a cross-domain instances. Then what about extending from a cross-domain class? The key is letting b.swf to load from a “proxy” class.
// http://domain3/c.swf
class Hund extends Tier {
//...
}
and
// http://domain3/c_proxy.swf _global["Tier"] = mc._parent.GetClassTier(); // call MovieClipLoader to load c.swf here
The reason you must have a proxy is bc AVM1 executes class definition in initClip stage when the loadee MovieClip is not available yet to access the loader MovieClip. If you try to extend from a class which was not in _global yet, it will never get a proper super value.
It’s ugly that you have to do such hack, while not so bad ‘cz you’re survived!
Cross-domain bug inside ActionScript 2.0
I believe it’s a bug: you turned off security check, it still tells you there’s a security violation when two swf read varibles from each other in certain way; however you end up finding that’s only a warning, you can still do it as is.
a.fla:
import System.security;
System.security.allowDomain("*");
function onLoadInit( mc:MovieClip ){
mc.test({test:"test"});
}
mcl = new MovieClipLoader();
mcl.addListener( this );
mcl.loadClip( "http://127.0.0.1/b.swf?"+Math.random(),
this.createEmptyMovieClip( "_container", this.getNextHighestDepth() ) );
b.fla:
import System.security;
System.security.allowDomain("*");
function test(o) {
trace("test func");
for(var i in o) { // violation happen here before any trace() below
trace(i);
}
}
Type http://localhost/a.swf, now you’ll get the buggy dump in log.In fact, there are an other couple of way to reproduce this, such as read/write an undefined member in a cross-domain object.
A new player to the desktop RIA playground?
With the release of
GTalk Lab Ed
, an desltop version of
GTalk Gadget
, Google has showed up its achievement of
WebKit
engine embedding. After Adobe AIR, Mozilla Prism and
some announcement
from m$, the search giant maybe also silently joined the Desktop RIA game. Will the
gears
finally become a
Porsche? Let’s guess…
File upload with URLRequest in AIR
A function to help upload without FileReference.upload() in AIR HTML/JS application.
Function Parameters:
void PrepareMultipartRequest(
URLRequest request,
ByteArray file_bytes,
string field_name = "file",
string native_path = "C:FILE",
object data_before = {},
object data_after = {}
);
Sample JS Code:
var request = new air.URLRequest('http://example.com/upload.php');
var loader = new air.URLLoader();
var file = new air.File('C:\TEST.TXT'); //use file.browseForOpen() on ur wish
var stream = new air.FileStream();
var buf = new air.ByteArray();
var extra = {
"id": "abcd"
};
stream.open(file, air.FileMode.READ);
stream.readBytes(buf);
MultipartRequest(request, buf, 'myfile', file.nativePath, extra);
loader.load(request);
Sample PHP Code:
$id = $_POST['id']; move_uploaded_file($_FILES['myfile']['tmp_name'], '/opt/blahblah');
Download:
multipart.js
Original idea inspired from
here
.