View comments | RSS feed

Using the #include directive

The #include directive is an ActionScript statement that copies the contents of the specified file into your MXML file. The #include directive uses the following syntax:

#include "file_name"

The following example includes the myfunctions.as file:

<mx:Script>
   <![CDATA[
      #include "myfunctions.as"
      ...
   ]]>
</mx:Script>

Note: The #include directive is a special kind of ActionScript statement. Do not end the line with a semicolon. If you do, you get a "Malformed #include directive" error message. In addition, you must surround the target file with quotation marks.

You can only specify a single file for each #include directive, but you can use any number of #include directives. You can next #include directives; files with #include directives can include files that have #include directives.

The #include directive supports only relative paths. For more information, see Referring to external files.

You can only use the #include where multiple statements are allowed. For example, the following is not allowed:

if (expr)
   #include "foo.as" // First statement is guarded by IF, but the rest are not.
...

The following is allowed:

if (expr) {
   #include "foo.as"  // All statements inside { } are guarded by IF.
}

The use of curly braces ({ }) allows multiple statements because you can add multiple statements inside the braces.

Macromedia recommends against using the #include directive if you use a large number of included ActionScript files. You should try to break the code into separate class files where appropriate and store them in logical package structures.


Version 1.5

Comments


mcorbridge said on Aug 18, 2005 at 2:23 PM :
typo
"you can next #include directives"
should be
"you can nest #include directives"

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000051.htm