Referencing ActionScript file - actionscript-3

I have a process set up to create action script files. They hold functions that are called upon by my flash project. How can i reference these files so that the project knows the functions are there.
with asp.net i would simply reference the .js file. Is it the same process?

The process of importing files to be used by Flash is pretty straightforward:
At the top of each external file there will be a package declaration, it basically represents it's path from the .fla file.
For example:
package com.site.objects
The above represents an ActionScript file within a folder objects, within site, within com whose parent folder also contains the .fla file.
When you're importing external files, you always start from the directory containing the .fla. This is always necessary with the exception of importing external files that are in the same directory as the file you're trying to access the class from.
The import statement for the above example will look like this:
import com.site.objects.MyClass;
Once you've done this, you'll be able to:
Create instances of the imported class.
Access static properties and methods defined within the class.
Extend the class to create a new class which will inherit it's properties.
etc

Related

Creating and Using a SWC File - Flash AS3

So I'm really confused on how to create, and use, a SWC file. I understand that a SWC file can be created to hold multiple assets. Basically, my code setup is the following:
c_Test.as - all testing of classes/fla files is done here
c_Test.fla - contains a few visual objects used/tested in c_Test.as
Class.as - class referenced multiple times in c_Test.as
Class1.fla - contains an important bitmap that is loaded into c_Test.as
So what I need to do is create a SWC file to be used in other projects; this is going to be the base of a multitude of other large projects, and I don't want to have to continuously copy and paste code into different folders. I am using Flash Builder 4.
So far, I went to publish settings in Flash CS6 in my c_Test.fla file and checked off Export SWF and Export SWC. What does this do? Has this created my SWC file?
I need to be able to access, from any random project, both Class.as, and Class1.fla.
Edit
So to clarify, cw_Test.fla is just a testing copy of the actual main fla file. I don't need this included in my swc. I just Exported my Class1.fla to SWf and SWC, and set a library path to the folder containing Class.as. Is this all I need to do to access both of these files from any project? (Besides importing them into any file I need them in).

Is it possible to generate a SWF from a documentClass file (.as) without having the original .fla?

I have inherited an Actionscript file from an old project and I've been told that it's possible to generate a SWF from it, though I don't have a corresponding FLA file.
The code within the file follows this form:
package {
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
// additional import statements
[SWF(width="640", height="480", frameRate="30", backgroundColor="#FFFFFF")]
public class MyClass extends Sprite {
// code, code, code
}
}
I have tried bringing this into Flash Builder and using "Run as Web Application" but I get a bunch of errors I don't understand (calls to undefined methods, definitions that can't be found).
I have done quite a bit of AS2 coding but not so much AS3 and zero Flex. I'm not sure if I am just not up to date on some of the latest methods for compiling SWFs without a corresponding FLA.
Is there a way to compile this type of file into a SWF? Or am I going about it the correct way but possibly just missing some dependent files?
Is it possible to generate a swf from an .as file without the original .fla:
Yes, IF you have all the dependencies.
When using flashBuilder, and you look at all your imports, anything that doesn't start with flash. or mx. is another file you'll need. This includes all imports within those class files as well.
Also, many .fla's use display objects that are in the library. If this is the case, those would need to be exported to another swc/swf and then linked/loaded to your flashBuilder project. That includes components (the 'fl' package).
So to sum it up:
If the original.fla is just an empty project with a document class linked, then you'll be fine if you have all the needed class files that are imported.
If the original .fla has library assets that are linked or dropped onto the timeline, then you will have issues if you can't get the original .fla.
How To Do This In Flash Builder
In flash builder, create a new ActionScript Project.
Put all the dependent files in the src folder of the project it just created - keeping their folder structure/hierarchy (the package name represents the folder it expects the .as file to be in relative to the src folder).
In the tree view, find the main .as file (documentClass), right click and tell it that it is the default application file (if you want, you can delete the file that was automatically generated when you created the project - projectname.as).
Run the project and it will put the swf in the bin (or bin-debug) folder with the same name as the project.

How To Reconfigure Class File Paths In a FLA File?

I have a lot of library assets linked to external as3 classes. I would like to change the structure of the packages containing the linked classes, but if I do so, all links will get broken.
Is there any way to automatically or at least easily tell the FLA file where to get the new class files from? Could a FLA file be configured to read this sort of information from a configuration file?
You can add a folder to the source paths in ActionScript Settings. So if you had linked all your classes relative to the 'myClasses' folder, and then you moved everything to a different folder, you'd just have to update that one source path and it would find all the classes again.
Also, maybe this obvious, but I didn't realize it for a long time:
You can edit the class linkage right in the Library panel (without having to open the Properties for each symbol). Just double-click the linkage path.

Change the include path for ActionScript

I am working on a custom library for Flash ActionScript3, and I have a handful of functions that I would like to add to Array.prototype.
I placed the extension in a separate .as file within a folder in the library directory, but when I make the include call from my document class, it tries to execute the include relative to the .fla file's location, rather than the library's source path.
I have already added the lib path to the Source Path: values under ActionScript3 Advanced Settings, which works for my import statements.
How do I get the include path to be relative to the library's path?
dir structure:
flash/
lib/libname/inc/array.as
projectname/project.fla
include that doesn't work (but should):
include "libname/inc/array.as";
include that works, but isn't portable if I move the project to a different location:
include "../lib/libname/inc/array.as";
I had a realization about how I was calling the include directive.
I had stored my document class in the same directory as the .fla file, because it's a class specific to the project. The document class contained the include directive, but the class that was actually using the extended Array functions was within lib/libname.
Moving the include directive to the .as file that required the extended features allowed the include directive to be called relative to the location of the calling class, which allowed me to use include "../inc/array.as"; because the .as file was within lib/libname/utils/ClassName.as.
So the answer to the issue is that the include path is relative to the location of the calling script, not the project. This means that any script within the library can include features from the library without issue, as the structure will be preserved.

How does the Gaia Flash Framework access the scaffold.as file?

In the Gaia Flash Framework, a file called 'Scaffold.as' is used to make each page a scaffold page. This is accessed by the code,
new Scaffold(this);
But the class itself does not appear to be imported. Am I missing something about the way flash handles external classes? Or is there something else pulling it in?
Any help appreciated.
This all depends on how you are compiling. I'll assume you are using Flash IDE to compile. Flash has a source path lookup mechanism. This can be accesed through the fla (under File->Publish Settings->Flash (tab)->ActionScript). If the file Scaffold lives at the root level of a class path then there is no need to import it. The default class path includes the directory the Flash file resides in and some Adobe directories. There is a mechanism for managing class packages ... I think it was the old Macromedia Extension Manager. It would copy classes into the default class paths when the package was installed - so that could be the case. I have no familiarity with Gaia itself.
So there are 3 options. First the file Scaffold.as is in the same directory as your fla. Second the file Scaffold.as is in a default Adobe include directory. Finally the file is in a directory referenced in the fla's class path.