I will miss you.
June 26th, 2009In memory of Michael Jackson.
In memory of Michael Jackson.
I know I am not the first to encounter this, but I thought it worth a mention anyway. I ran in to an issue loading a module from with in a module using flex. The module would load, but the ModuleEvent.READY would not fire. The instance of the module was ready and setup was true. WTF!!! why! After searching the net I came across this bug https://bugs.adobe.com/jira/browse/SDK-14669. It said a workaround is to load all the modules sequentially. Now I know this sucks because 1 by 1 is not exactly a model of efficiency. Anyhoo…I threw the following class together and thought it would help:
/**
* this class is to get around this bug
* https://bugs.adobe.com/jira/browse/SDK-14669
* when we move to gumbo (flex 4) the bug will be fixed
* */
package com.timothyhuertas.utils
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.utils.ByteArray;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
public class SequentialModuleLoader extends EventDispatcher
{
private static var _instance:SequentialModuleLoader;
private var _pool:Array;
private var _current:IModuleInfo;
public function SequentialModuleLoader(value:SingletonEnforcer)
{
_pool = new Array();
}
public static function get instance() : SequentialModuleLoader
{
if(!_instance)
{
_instance = new SequentialModuleLoader(new SingletonEnforcer());
}
return _instance;
}
public function load(info:IModuleInfo, applicationDomain:ApplicationDomain=null, securityDomain:SecurityDomain=null, bytes:ByteArray=null) : void
{
var queued:Object = new Object;
queued.info = info;
queued.applicationDomain = applicationDomain;
queued.securityDomain = securityDomain;
queued.bytes = bytes;
_pool.push(queued);
processPool();
}
protected function processPool() : void
{
if(_pool.length && _current==null)
{
var queued:Object = _pool[0];
_pool.splice(0,1);
_current = queued.info as IModuleInfo;
_current.addEventListener(ModuleEvent.READY, handleModuleResponse, false,0,true);
_current.addEventListener(ModuleEvent.ERROR, handleModuleResponse, false,0,true);
_current.load(queued.applicationDomain, queued.securityDomain, queued.bytes);
}
}
protected function handleModuleResponse(e:ModuleEvent) : void
{
IEventDispatcher(e.target).removeEventListener(e.type, handleModuleResponse);
_current = null;
processPool();
}
}
}
class SingletonEnforcer{}
An example of its usage is as follows:
var m:IModuleInfo = ModuleManager.getModule("Mod1.swf");
m.addEventListener(ModuleEvent.READY, modLoaded);
SequentialModuleLoader.instance.load(m,ApplicationDomain.currentDomain);
protected function modLoaded(e:ModuleEvent):void
{
IEventDispatcher(e.target).removeEventListener(e.type, modLoaded);
IModuleInfo(e.target).factory.create();
}
I hope this helps
Which comment is more gangster? “Now you’s can’t leave” or “Look at me. I’m the one who did this to you. Remember me.”
I am working on a project that requires me to deploy files to Firefox’s plugins directory. The biggest challenge was finding the location of this directory. People can have multiple versions of Firefox and may change the default install location. Since the project targets Windows machines a coworker recommended reading the registry. The idea sounded good, but it had been a while since I had cracked C++ (let alone Visual C++). So I took to the web for some examples. I came across this (http://msdn.microsoft.com/en-us/library/ms235431.aspx) on Microsoft’s web site. It is a list of sample code for various Visual C++ tasks. It helped me throw this together. Below is source for a program that will write out every installed version of Firefox along with the location of the plugins directory. Enjoy….
// registry_read.cpp
// compile with: /clr
using namespace System;
using namespace Microsoft::Win32;
int main( )
{
RegistryKey^ rk = nullptr;
rk = Registry::LocalMachine->OpenSubKey(”SOFTWARE”)->OpenSubKey(”Mozilla”);
array
for ( int i = 0; i < subKeyNames->Length; i++ )
{
RegistryKey ^ tempKey = rk->OpenSubKey( subKeyNames[ i ] );
RegistryKey ^ extensionKey = tempKey->OpenSubKey( “extensions” );
if (extensionKey!=nullptr)
{
Console::WriteLine( “\nFound {0} here is the plugins dir {1}.”, tempKey->Name, extensionKey->GetValue( “Plugins” )->ToString() );
}
}
return 0;
}
This is awesome on both a comic and technical level.
Ummm…This was a surprise. Did anyone see this coming?
Oh and you gotta love this guy’s reaction: