2013-08-07 45 views
0

我從來沒有遇到問題,通過Htmlloader的頁面歷史記錄瀏覽Back和Forward,這是主Native Window階段的子項。我只需要使用:HtmlLoaderVariable.historyForward();HTMLLoader:在頁面歷史中導航後退和前進

但是,當我將HTMLLoader作爲一個孩子添加到一個新的本機窗口,它似乎並沒有工作。

下面是代碼:

function createNewHtmlWindow(pageUrl:String):void{ 
    //Everytime I click a button, this function creates a seperate Native Window each containing HtmlLoader Class to load a webpage 

    var myhtml= new HTMLLoader(); 
    myhtml.width = 1000; 
    myhtml.height = 780;  
    myhtml.addEventListener(Event.COMPLETE, myHtmlLoaded); 


    var myHtmloptions = new NativeWindowInitOptions(); 
    myHtmloptions.transparent = false; 
    myHtmloptions.systemChrome = NativeWindowSystemChrome.STANDARD; 
    myHtmloptions.type = NativeWindowType.NORMAL; 

    var extHtmlWindow = new NativeWindow(myHtmloptions);  
    extHtmlWindow.title="new title"; 
    extHtmlWindow.width = 1015; 
    extHtmlWindow.height = 800; 

    extHtmlWindow.activate(); 
    extHtmlWindow.stage.align = "TL"; 
    extHtmlWindow.stage.scaleMode = "noScale"; 
    extHtmlWindow.stage.addChild(myhtml); 

    var backNativeWin=new BackButton(); 
    backNativeWin.x=5; 
    backNativeWin.y=500; 
    backNativeWin.addEventListener(MouseEvent.CLICK, loadPrevHistory); 
    extHtmlWindow.stage.addChild(backNativeWin); 

    var nextNativeWin=new NextButton(); 
    nextNativeWin.x=30; 
    nextNativeWin.y=500;  
    nextNativeWin.addEventListener(MouseEvent.CLICK, loadNextHistory); 
    extHtmlWindow.stage.addChild(nextNativeWin); 

    myhtml.load(new URLRequest(pageUrl)); 
} 

function myHtmlLoaded(e:Event):void 
{ 
    //Page loads successfully 

} 


function loadNextHistory(m:MouseEvent):void{ 
    output.text="Next>>"+m.target.parent.getChildAt(0); //Next>>[object HTMLLoader] 
    m.target.parent.getChildAt(0).historyForward(); // This line is not working 


} 

function loadPrevHistory(m:MouseEvent):void{ 
    output.text="Prev>>"+m.target.parent.getChildAt(0); //Prev>>[object HTMLLoader] 
    m.target.parent.getChildAt(0).historyBack(); // This line is not working 

} 
+0

不知道這是什麼原因引起的問題,但是你應該避免使用'parent'屬性來運行一個命令。你永遠不想向後遍歷顯示列表(或OOP語言中的任何對象樹),只能轉發。唯一一次應該使用'parent'屬性是爲了檢查父對象是否存在或父對象的數據類型是什麼。您應該將引用保存爲可用對象的屬性。 –

+0

你是對的喬希。我通過將父引用爲屬性來實現它,然後使用getChildAt(0)。謝謝 –

回答

1

我已經試過你的代碼我自己的網頁,它工作得很好.. 這裏是我的代碼:

import flash.html.HTMLLoader; 
import org.aswing.JButton; 
import flash.filesystem.File; 

function createNewHtmlWindow(pageUrl:String):void{ 
//Everytime I click a button, this function creates a seperate Native Window each containing HtmlLoader Class to load a webpage 

var myhtml= new HTMLLoader(); 
myhtml.width = 1000; 
myhtml.height = 680;  
myhtml.addEventListener(Event.COMPLETE, myHtmlLoaded); 


var myHtmloptions = new NativeWindowInitOptions(); 
myHtmloptions.transparent = false; 
myHtmloptions.systemChrome = NativeWindowSystemChrome.STANDARD; 
myHtmloptions.type = NativeWindowType.NORMAL; 

var extHtmlWindow = new NativeWindow(myHtmloptions);  
extHtmlWindow.title="new title"; 
extHtmlWindow.width = 1015; 
extHtmlWindow.height = 700; 

extHtmlWindow.activate(); 
extHtmlWindow.stage.align = "TL"; 
extHtmlWindow.stage.scaleMode = "noScale"; 
extHtmlWindow.stage.addChild(myhtml); 

var backNativeWin:JButton=new JButton("back"); 
backNativeWin.setSizeWH(100,22); 
backNativeWin.x=5; 
backNativeWin.y=500; 
backNativeWin.addEventListener(MouseEvent.CLICK, loadPrevHistory); 
extHtmlWindow.stage.addChild(backNativeWin); 

var nextNativeWin=new JButton("next"); 
nextNativeWin.setSizeWH(100,22); 
nextNativeWin.x=130; 
nextNativeWin.y=500;  
nextNativeWin.addEventListener(MouseEvent.CLICK, loadNextHistory); 
extHtmlWindow.stage.addChild(nextNativeWin); 

myhtml.load(new URLRequest(pageUrl)); 
} 

function myHtmlLoaded(e:Event):void{ 
//Page loads successfully 
} 


function loadNextHistory(m:MouseEvent):void{ 
trace("Next>>"+m.target.parent.getChildAt(0)); //Next>>[object HTMLLoader] 
m.target.parent.getChildAt(0).historyForward(); // This line is not working 
} 

function loadPrevHistory(m:MouseEvent):void{ 
trace("Prev>>"+m.target.parent.getChildAt(0)); //Prev>>[object HTMLLoader] 
m.target.parent.getChildAt(0).historyBack(); // This line is not working 

} 
createNewHtmlWindow(File.desktopDirectory.resolvePath("index.html").url); 

而這裏的指數。 HTML我的桌面上:

<html> 
<head> 
    <title>This is a test page</title> 
</head> 
<body> 
    <a href="http://www.google.com">Click me to jump to Google.</a> 
</body> 

所以我認爲你的測試網站一定有什麼問題,換另一個再試一次可能會有所幫助..

+0

網站沒有錯。它只是引發問題的parent.getChildAt(0)的引用。它必須被引用爲屬性。現在它的工作 –