我在Flash中启动第二个窗口时遇到了一些麻烦。
我已经有了第二个屏幕工作,当我使用触摸屏来播放其中的元素时,它的速度非常慢,我得出的结论是由于我的计算机资源使用不当(不超过15%的CPU使用率,低于10%的内存且没有使用GPU)。
有任何想法如何改善这个问题?
我想到了工人,一名工人正在处理主屏幕而另一名工人正在处理de秒,但我无法让工人和第二个屏幕正常工作。
以下是我的一些代码:
- MAIN -
public function activateSecondScreen(evt:Event = null):void{
if(Worker.current.isPrimordial && firstTime){
firstTime = false;
initWorker();
}
//If not the main thread, we're the worker
else {
secondaryWindow = new SecondWindow();
}
}
protected function initWorker():void {
//Create worker
worker = WorkerDomain.current.createWorker(loaderInfo.bytes,true);
worker.addEventListener(Event.WORKER_STATE,activateSecondScreen);
//Create message channel TO the worker
mainToBack = Worker.current.createMessageChannel(worker);
//Create message channel FROM the worker, add a listener.
backToMain = worker.createMessageChannel(Worker.current);
backToMain.addEventListener(Event.CHANNEL_MESSAGE, onBackToMain, false, 0, true);
//Now that we have our two channels, inject them into the worker as shared properties.
//This way, the worker can see them on the other side.
worker.setSharedProperty("backToMain", backToMain);
worker.setSharedProperty("mainToBack", mainToBack);
//Lastly, start the worker.
if (worker.state != WorkerState.RUNNING)
{
worker.start();
}
}
protected function onBackToMain(event:Event):void {
var msg:String = backToMain.receive();
if(msg == "SHARPEN_COMPLETE"){
//Futures Uses
}
trace(msg);
}
我希望我的工作人员启动SecondScreen对象。
- SECONDSCREEN.AS - 公共类SecondWindow扩展了Sprite {
public var secondWindow:NativeWindow;
public function SecondWindow()
{
super();
initSecondWindow();
}
private function initSecondWindow():void{
var secondWindowinitOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
secondWindowinitOptions.transparent = true;
secondWindowinitOptions.systemChrome = NativeWindowSystemChrome.NONE;
secondWindowinitOptions.type = NativeWindowType.UTILITY;
secondWindowinitOptions.renderMode = NativeWindowRenderMode.GPU;
secondWindow = new NativeWindow(secondWindowinitOptions);
secondWindow.title = "Second Window";
secondWindow.alwaysInFront = false; //true
var activar:Boolean = false;
var screenArray:Array = Screen.screens;
for(var i:int = 0 ; i< screenArray.length ; i++){
if(screenArray[i].bounds.x != 0 || screenArray[i].bounds.y != 0){
secondWindow.bounds = (screenArray[i] as Screen).bounds; //TODO:
activar = true;
}
}
secondWindow.stage.displayState = StageDisplayState.FULL_SCREEN;
secondWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
secondWindow.stage.align = StageAlign.TOP_LEFT;
secondWindow.activate();
}
}
这样我想打开一个新窗口,以便稍后传递一些图像,视频或其他内容。
行secondWindow.activate();
无法正常工作,没有工作人员的相同代码会启动窗口。
我很感激任何想法。
谢谢。