网页中使用#include 指令

#include "[path]filename.as":String

包括指定文件的内容,就像该文件中的命令是调用脚本的一部分一样。#include 指令在编译时调用。因此,如果对外部文件进行了任何更改,则必须保存该文件,并重新编译任何使用它的 FLA 文件。

如果对包含 #include 语句的脚本使用"语法检查"按钮,则也会检查所包括文件的语法。

您可以在 FLA 文件和外部脚本文件中使用 #include,但不能在 ActionScript 2.0 类文件中使用。

您可以对要包括的文件不指定路径、指定相对路径或指定绝对路径。如果您不指定路径,则 AS 文件必须位于以下位置之一:

  • 与 FLA 文件位于同一个目录。与包含 #include 语句的脚本位于同一个目录。
  • 全局 Include 目录,该目录为以下目录之一:- Windows 2000 或 Windows XP:C:\Documents and Settings\用户\Local Settings\Application Data\Macromedia\Flash 8\语言\Configuration\Include- Macintosh OS X:Hard Drive/Users/Library/Application Support/Macromedia/Flash 8/语言/Configuration/Include
  • Flash 8 程序\语言\First Run\Include 目录;如果您在此目录中保存一个文件,则在下次启动 Flash 时,会将此文件复制到全局 Include 目录中。

若要为 AS 文件指定相对路径,请使用单个点 (.) 来指示当前目录,使用两个点 (..) 来指示父级目录,并使用正斜杠 (/) 来指示子目录。请参见以下示例部分。

若要为 AS 文件指定绝对路径,请使用您的平台(Macintosh 或 Windows)所支持的格式。请参见以下示例部分。(不建议使用此方法,因为此方法要求任一编译此脚本的计算机上均具备相同的目录结构。)

如果您将文件放在 First Run/Include 目录或全局 Include 目录中,请备份这些文件。如果您需要卸载或重新安装 Flash,可能会删除和覆盖这些目录。

不要将分号 (;) 放在包含 #include 指令的行的末尾。

可用性:Flash Player 4.0;ActionScript 1.0

参数

[path]filename.as:String - filename.as要添加到"动作"面板或当前脚本中的脚本的文件名和可选路径;.as 是推荐使用的文件扩展名。

示例

下列示例说明指定要包含在脚本中的文件的路径的各种方法:

// Note that #include statements do not end with a semicolon (;)
// AS file is in same directory as FLA file or script
// or is in the global Include directory or the First Run/Include directory
#include "init_script.as"

// AS file is in a subdirectory of one of the above directories
// The subdirectory is named "FLA_includes"
#include "FLA_includes/init_script.as"
// AS file is in a subdirectory of the script file directory
// The subdirectory is named "SCRIPT_includes"
#include "SCRIPT_includes/init_script.as"
// AS file is in a directory at the same level as one of the above directories
// AS file is in a directory at the same level as the directory
// that contains the script file
// The directory is named "ALL_includes"
#include "../ALL_includes/init_script.as"

// AS file is specified by an absolute path in Windows
// Note use of forward slashes, not backslashes
#include "C:/Flash_scripts/init_script.as"

// AS file is specified by an absolute path on Macintosh
#include "Mac HD:Flash_scripts:init_script.as"

include在网页制作中的使用既简单又灵活,它不但能减少页面的繁琐,也会使管理变得更有序和有效,许多朋友都在问是否能动态的使用include?在这里我再强调一下,<!--#include file="<%fileName%>"--> 是绝对行不通的,要是使用
<%if xxx = "yyy" then%>
<!--#include file="file1.asp"-->
<%else%>
<!--#include file="file2.asp"-->
<%end if%>

这无形中会下载没有必要的档案,影响载入网页的速度。如何解决这个问题呢?我所知道的有以下方法:
<%
1)
If xxx = "yyy" Then
Server.Execute("file1.asp")
Else
Server.Execute("file2.asp")
End If

2)
If xxx = "yyy" Then
Server.transfer("file1.asp")
Else
Server.transfer("file2.asp")
End If

3)
if xxx = "yyy" then
filespec = "file2.asp"
else
filespec = "file2.asp"
end if
filespec = server.mapPath(filespec)
scr = "scripting.fileSystemObject"
set fs = server.createobject(scr)
set f = fs.openTextFile(filespec)
content = f.readall
set f = nothing
set fs = nothing
response.write(content)
%>

我要说明的就是,如果使用以上方法来实现include功能的时候,必须注意的地方。
我们可以将<!--#include file="file.asp"-->中被包含的网页file.asp看成是包含了file.asp的网页的有机组成部分,只是将本来属于该网页的内容以另一个档案形式保存罢了,可以这样说他们本来就是一个网页,所以,被包含的网页file.asp继承了包含了file.asp的网页的所有的参数设定,包括Session 但是,其他的方法并非如此,在html语法部分可以和主网页共享,asp部分却是独立的,特别的Session在一般情况下是不能从主网页中传递到被包含的网页file.asp来,这点很重要,使用时要注意。

你可能感兴趣的:(windows,脚本,Flash,asp,actionscript)