project.addFile()

Availability

Flash 8.

Usage

project.addFile(fileURI [ , autoCreateFolder])

Parameters

fileURI A string specifying the file to be added to the project, expressed as a file:/// URI.

autoCreateFolder An optional Boolean value specifying if folders should be automatically created in the Project panel to mirror the path in fileURI; the default value is false.

Returns

If successful, returns a ProjectItem object; otherwise, returns undefined. See ProjectItem object.

Description

Method; adds the specified file to the project. You can use autoCreateFolder to determine where the new file should be positioned in the Project panel:

Example

The following example illustrates several ways to use this command. In this case, the open project file is in the c:\Projects directory, and the only files currently in the project have been added at the root level.

// Get the project object.
var myProject = fl.getProject();
// The following command creates a folder named "files" below the root level in the project, and places myFile.fla in that folder.
var newFile = myProject.addFile("file:///C|Projects/files/myFile.fla", true)
fl.trace(newFile.isMissing); // false
// The following two commands have the same effect: placing myFile_02.fla in the root level of the project.
var newFile = myProject.addFile("file:///C|Projects/files/myFile_02.fla" , false)
var newFile = myProject.addFile("file:///C|Projects/files/myFile_02.fla")
fl.trace(newFile.isMissing); // false
// The following command places myFile_03 in the root level of the project as a missing file.
var newFile = myProject.addFile("file:///C|myFile_03.fla")
fl.trace(newFile.isMissing); // true

The following example attempts to add a new file to the project, and displays a message in the Output panel indicating whether the file was added:

var myProject = fl.getProject(); 
var newItem = myProject.addFile("file:///C|Projects/files/Integra.fla", true);
fl.trace( "Item " + ( newItem ? "was" : "was not" ) + " added!" );

See also

fl.getProject(), project.items, ProjectItem object