local - remote ( trace(loader.content is BaseScene) ) удалось победить только через Loader#loadBytes.
Добавлено через 10 минут
Не сталкивался в своих проектах с таким случаем. Мы делаем приложение, файлы ресурсов которого находятся на локальной машине, затем при релизе дружно выливаются на сервер. В этом случае, если вид песочниц у ресурса и загрузчика одинаков (local - local и remote - remote), то проблем с приведением нет.
Добавлено через 59 минут
Получился такой вот "всеядный" загрузчик.
Код AS3:
/*
The MIT License,
Copyright (c) 2011. Dimarik
*/
package
{
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.system.SecurityDomain;
import baseSceneClasses.BaseScene;
/**
* @author Dimarik
* @version 1.0
* @langversion 3.0
* @playerversion 9.0
*
*/
[SWF(width="800", height="600", frameRate="21", backgroundColor="#E0EEEE")]
public class ClassSubstitutionTest extends Sprite {
//-------------------------------------------------------------------------
//
// Constructor
//
//-------------------------------------------------------------------------
public function ClassSubstitutionTest() {
super();
super.addEventListener(Event.ADDED_TO_STAGE, this.creationComplete);
}
//-------------------------------------------------------------------------
//
// Private variables
//
//-------------------------------------------------------------------------
/**
* @private
*/
private const _isRemote:Boolean = Security.sandboxType == Security.REMOTE;
//-------------------------------------------------------------------------
//
// Private methods
//
//-------------------------------------------------------------------------
private function creationComplete(event:Event):void {
super.removeEventListener(event.type, arguments.callee);
const loader:Loader = new Loader();
const li:LoaderInfo = loader.contentLoaderInfo;
li.addEventListener(Event.COMPLETE, this.handler_complete, false, int.MAX_VALUE);
li.addEventListener(Event.COMPLETE, this.handler_publicComplete);
const lcxt:LoaderContext = this._isRemote ? new LoaderContext(false, null, SecurityDomain.currentDomain) : null;
//loader.load( new URLRequest('http://example.com/module3.swf'), lcxt );
//loader.load( new URLRequest('module3.swf'), lcxt);
}
//-------------------------------------------------------------------------
//
// Event handlers
//
//-------------------------------------------------------------------------
/**
* @private
* Основной обработчик
*/
private function handler_publicComplete(event:Event):void {
const li:LoaderInfo = event.target as LoaderInfo;
li.removeEventListener(Event.COMPLETE, arguments.callee);
const test:BaseScene = li.loader.content as BaseScene; // Bingo!
}
/**
* @private
* Вспомогательный обработчик
*/
private function handler_complete(event:Event):void {
const li:LoaderInfo = event.target as LoaderInfo;
li.removeEventListener(Event.COMPLETE, arguments.callee);
if (
!li.sameDomain
&& !this._isRemote
) {
event.stopImmediatePropagation();
li.loader.loadBytes(li.bytes);
}
}
}
}