Relative URLs in Actionscript 3

前端 未结 3 1001
名媛妹妹
名媛妹妹 2021-01-14 12:53

I have a flash movie using Actionscript 3 with some buttons that open links to new pages. Here is the code I have for redirecting to the new page:

myButton.a         


        
相关标签:
3条回答
  • 2021-01-14 13:05

    URLRequests are relative to the HTML file containing them (it doesn't matter where your SWF is), so you need to take that into account. There is an optional attribute of the EMBED/OBJECT that you can set to change this behaviour, see here:

    base - . or [base directory] or [URL]. Specifies the base directory or URL used to resolve all relative path statements in the Flash Player movie. This attribute is helpful when your Flash Player movies are kept in a different directory from your other files.

    http://kb2.adobe.com/cps/127/tn_12701.html

    EDIT: Also, try to avoid using absolute URLs for relative files, as you could get sandbox errors, for instance, loading the web without "www."...

    0 讨论(0)
  • 2021-01-14 13:13

    /page2.html should work fine as Chris suggested.

    Also, one thing I often do for larger projects with lots of URL's is simply create a set of global link functions that I can switch between for different launch environments.

    Where I work we have at least 4 or 5 different environments between production, staging, and various testing environments, and sometimes URL's have to be tweaked (for example, if a data source is on staging and not on production yet).

    So I would make a high level function like

    MakeURL()

    Which I would feed a base page string such as "page2.html", and the MakeURL function would parse in a URL prefix such as http://staging.site.com or http://alpha.site.com.

    That way if I had to, I could change every link in the app quickly.

    Now, you rarely need to put the entire URL in there unless you are working with multiple and varied environments. Usually /page2.html will work, but I use that function sometimes as a failsafe.

    0 讨论(0)
  • 2021-01-14 13:24

    Try using /page2.html

    0 讨论(0)
提交回复
热议问题