这里记录一个小的知识点,其实也不是经常用到但是,用到了的时候确实觉得有点蹊跷了,元芳你怎么看,
我们在用一个testA.swf作为加载器去用Loader方法去加载另外一个testB.swf,而这个被加载的swf调用了一个本地存储的方法,就是我们大名鼎鼎的SharedObject了,但是在我们去查看本地缓存的时候发现这个testB.swf的存储路径是在testA.swf的目录下面的。
C:\Users\Benny\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\..\..\flash\testA.swf
但是,当我们用个URLStream去加载的时候是可以保存在testB.swf目录下面的。
C:\Users\Benny\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\..\..\flash\testB.swf
这里附上源码
加载器testA
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.SharedObject;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.utils.ByteArray;
public class Test5 extends Sprite
{
private var __loader :Loader;
private var __urlLoader :URLStream;
public function Test5()
{
__urlLoader = new URLStream();
__urlLoader.addEventListener(Event.COMPLETE, urlLoaderCompleteHandler );
__urlLoader.load( new URLRequest( "Test6.swf" ) );
__loader = new Loader();
__loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler );
}
protected function urlLoaderCompleteHandler(event:Event):void
{
// TODO Auto-generated method stub
var bytes :ByteArray = new ByteArray();
__urlLoader.readBytes( bytes );
__loader.loadBytes( bytes );
}
private function loadCompleteHandler( event:Event ):void
{
}
}
}
被加载对象testB.swf
package
{
import flash.display.Sprite;
import flash.net.SharedObject;
public class Test6 extends Sprite
{
public function Test6()
{
init();
}
public function init():void
{
SharedObjectUtils.setValue( "value", 1234546 );
}
}
}
下面是一个简单的utils
package
{
import flash.net.SharedObject;
public class SharedObjectUtils
{
static private var __localShared :SharedObject;
static private function get localShared():SharedObject
{
if( __localShared == null )
__localShared = SharedObject.getLocal( "test" );
return __localShared;
}
static public function getValue( key:String ):Object
{
return localShared.data[ key ];
}
static public function setValue( key:String, value:Object ):void
{
localShared.data[ key ] = value;
localShared.flush();
}
}
}