如何使用navigateToUrl访问相对于站点根目录的html文件?

时间:2010-10-26 13:42:41

标签: actionscript-3 flash-cs5

我尝试在网站内制作一个介绍动画,当动画完成或按下“跳过”按钮时,它会从站点根目录导航到index.html文件。

所以我在我的站点根目录下有文件夹Flash,其中是intro.swf,并且在intro.swf中我调用了navigateToURL(new URLRequest("..\index.html"), "_self");方法。现在它不起作用。你能说出如何定义URL请求吗?

感谢。

3 个答案:

答案 0 :(得分:1)

你知道,我曾经在Flex中遇到过一个奇怪的范围问题。解决方案是通过手动解析loaderInfo.loaderURL来强制使用绝对URL。一个简单的版本可能是:

function getAbsoluteURL( pathFromSwf:String, swfURL:String ):String
{
    // if pathFromSwf is already a URL, then just return that.
    if( pathFromSwf.match( /^(http.{3}[^\/]{5,})\/(.*)$/ ) ) return pathFromSwf;
    // this may need to be customized based on your extension/server settings.
    var basePath:Array = swfURL.substr( 0, swfURL.indexOf( ".swf" ) ).split( "/" );
    basePath.pop(); // clear out the swf's name.
    var altPath:Array = pathFromSwf.split( "/" );
    for( var i:int = 0; i < altPath.length; i++ )
    {
        // ".." subtracts from the path/
        if( altPath[ i ] == ".." ) basePath.pop();
        // otherwise append
        else basePath.push( altPath[ i ] );
    }
    return basePath.join( "/" );
}

答案 1 :(得分:1)

你试过这个:

navigateToURL(new URLRequest("../index.html"), "_self");

使用反斜杠只是一个错字吗?

答案 2 :(得分:0)

您的swf文件的位置:

loaderInfo.loaderURL