2012-08-14 37 views
0

讓我來解釋一下我的問題。如何使預加載的swf填充瀏覽器?

我正在創建一個flash網站,我正在使用一個小的外部預加載器swf加載主swf。我已經能夠讓我的預加載器SWF佔據整個瀏覽器窗口,但一旦加載到主SWF中,它只會以其正常尺寸顯示它是內置的。

我確實有一個調整大小的偵聽器主要的Flash應用程序,只要我改變瀏覽器的大小,主要的SWF佔用整個瀏覽器。但是,我怎麼才能以這種方式開始呢?

- 我曾嘗試使用ENTER_FRAME處理程序,但這打破了我的一些動畫。 - 我試過在預加載器中設置我的加載器對象的寬度和高度,但似乎也沒有工作。 - 我也試着給加載器添加一個ADDED_TO_STAGE監聽器,但是這似乎沒有改變任何東西。 - 我還試圖讓preloader在一個場景中,主應用程序在另一個場景中,以便我只加載一個swf,但這似乎不起作用,我不喜歡這種預加載方法。

我一直無法找到解決方案。有什麼容易的,我錯過了?讓我知道你們都在想什麼。預加載器代碼如下:

import flash.net.URLRequest; 
import flash.display.Loader; 
import flash.events.Event; 
import flash.events.ProgressEvent; 

var request:URLRequest = new URLRequest("flashNew.swf"); 
var loader:Loader = new Loader(); 


loader.load(request); 
this.addChild(loader); 


function loadProgress(event:ProgressEvent):void 
{ 
    var percentLoaded:Number = event.bytesLoaded/event.bytesTotal; 
    var percentLoadedBar:Number = Math.round((event.bytesLoaded/event.bytesTotal) * 100); 
    percentLoaded = Math.round(percentLoaded * 100); 

    this.percentLoaded.text = String(uint(percentLoaded)) + "%"; 

    progressBar.width = percentLoadedBar * 3.36; 
} 

function loadComplete(event:Event):void 
{ 
    //loader.content.height = stage.stageHeight; 
    //loader.content.width = stage.stageWidth; 
} 

function setDimensions(event:Event):void 
{ 
    loader.width = stage.stageWidth; 
    loader.height = stage.stageHeight; 
} 

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress); 
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); 
loader.contentLoaderInfo.addEventListener(Event.ADDED_TO_STAGE, setDimensions); 

有沒有一種方法可以通過javascript或其他方式更改?我在這裏感到不知所措,而且我一直堅持這幾個小時。任何幫助,將不勝感激。謝謝!

UPDATE 這是我的代碼,用於我的調整大小功能。

function resizeListener(e:Event):void 
{ 
    background_mc.width = stage.stageWidth; 
    background_mc.height = stage.stageHeight; 
    //The rest of the function is omitted. It is if's and else-if's that just reposition various elements. 
    //That's really all this function does is re-position elements with the exception of the above code which resizes the background. 
} 

這裏是事件監聽器調用。

stage.addEventListener(Event.RESIZE, resizeListener); 
+0

如果你更新你的問題,包括這將是很好你的代碼在html頁面中調整你的swf大小。 – BadFeelingAboutThis 2012-08-14 22:30:54

+0

與你的問題沒有關係,但是一個好的做法,是在你調用loader.load()之前添加你的loader.contentLoaderInfo事​​件監聽器() – BadFeelingAboutThis 2012-08-14 22:32:37

回答

0

試試這個:

刪除這行代碼:this.addChild(loader);

然後調整你的loadComplete功能如下:

function loadComplete(event:Event):void 
{ 
    addChild(loader.content); 
    loader.content.height = stage.stageHeight; 
    loader.content.width = stage.stageWidth; 
} 
+0

我剛試過這個。似乎沒有工作。 :\ – linkian19 2012-08-14 23:32:59

+0

你有什麼地方可以訪問你的頁面嗎? – BadFeelingAboutThis 2012-08-14 23:44:05

+0

是的。轉到:http://istanek.com/SoundRehabStudios/index.html正如你可以看到當新的swf被加載時它會填充瀏覽器(至少不是我的在1920x1080),你可以看到我的一些元素隱藏舞臺。我知道我可以用阿爾法或可見的方式隱藏它們,但是暫時更容易。 – linkian19 2012-08-14 23:47:05