i just wanna access the public class which is 2 levels outside from the fla file. My folder structure as follows.
com
displays
main.fla
Some fla's are located in displays folder. And i want to access the globalvar.as from fla's which is located in displays folder.
Before anyone can help you - you need to get your terminology right. You want to access a class programatically, not an '.as' file (even if the .as file contains the definition of the class). And you want to access it from another class, not from a '.fla' file.
Anyway, what you need to do it import globalvar.as in the class that needs to access it, and (assuming it's a static class, which it should be) just access it like this globalvar.myVarName (where 'globalvar' is the case-sensitive name of the class, and 'myVarName' is the name of the var you want to access).
Using an IDE like Flash Builder (which is an excellent product) makes this sort of thing much easier - if you're interested in AS3 development I would really recommend it.
Related
I want to know how to load external class files(.as files) in actionscript but don't have to know the class file's name. Think of it like loading mods in minecraft with forge mod loader, it doesn't know the main class of the mod's file name, yet it successfully loads the mod. I want to know if something like this is possible in actionscript 3.0 because I feel like making a tower defense game that isn't like the others out there but have it so it can be modded and have mods loaded but of course I have to load the class file without knowing the class file's name.
Note: I don't got access to Adobe Air so I can't use anything that requires Adobe Air.
You want to load a particular .as file AFTER or BEFORE compilation? After the compilation it is hardly possible - the file would not be compiled and therefore it would be useless. Why don't you use a swf or some kind of XML/JSON with settings in that case? Before the compilation you would still need to identify it by it's package name/name.
Basically, you want a plugin management system.
In AS3, it is not possible to "load" a .as file on execution, because it is a (uncompiled) source file. But, it is possible to load another swf and to use the classes within it.
Your process should probably be something like this :
Get a list of the plugins/addons. If you were using AIR, it would have been possible by browsing the content of a folder. Since you're not, you'll probably need to use a listing file (basically, a file that say "Here's the list&path of the plugins you need to load".
Load each swf file
(possibly) call a initialization method for each plugin.
You may wish to look into the way OSMF manages plugins, for example : http://osmf.org/dev/osmf/OtherPDFs/osmf_plugin_dev_guide.pdf
I have a question:
I have in Fla Library a object with the Class property like: com.tool.zoom linked to external as.
In timeline i call with:
mainApp.iniZoom("com.tool.zoom");
This fla is loaded in another FLA on I call iniZoom function.
It is posible? I get error 1007.
I hope you understand me, my english is not really good.
Thanks!
As I understand you, you are trying to instantiate a class exported from a FLA file. You select that object, do Export for Actionscript, and name class "com.tool.zoom", right? If so, you should use "new" clause like this:
var iniZoom:com.tool.zoom = new com.tool.zoom();
Obviously you need to have the AS file available at compile time.
Edit: given that you load the SWF, here is the solution that might work for you. Note you have to load all the classes you want to export from the SWF for your parent SWF to be available.
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.
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
I'm having trouble accessing content in an SWC. The main project compiles without error, but the assets (sound, music) aren't displayed or played.
My workflow:
i. Using Flash CS5
1. Create MAsset.fla
2. Import sounds, art
3. Assign class names, check export in frame 1
4a. Write out the classes in the actions panel in frame 1
4b. OR. Add a document class and write out the classes there
5. Export SWC. Filesize is similar to what it is when I directly import assets in the main project library.
6. Create Project.fla and document class Project.as
7. Import SWC into main project through the Actionscript panel.
8. Add code, which calls the class names from the SWC (e.g. DCL_UI_MOUSE)
9. Compile.
No compiler errors, but nothing doing. And the resulting SWF filesize doesn't reflect anything more than the compiled code from the main project.
Regarding step 4, if I just write the class name in the root timeline or document class, the compiler error will go away and the asset appear to be compiled in the SWC. But I have also tried:
var asset0000:DCL_UI_MOUSE;
And:
var asset0000:DCL_UI_MOUSE = new DCL_UI_MOUSE();
Regardless the assets don't make it into the final SWF.
What am I doing wrong?
What exactly do you mean when you say "Import SWC into the main project through the ActionScript panel" and "Add code, which calls the class names from the SWC"?
If you want to use an SWC as an asset library, you have to
add the SWC to the library path, and
always add the appropriate import statements to your ActionScript code.
There's no step threeâ„¢.
You can also use it as a runtime shared library by linking to individual library objects in the properties panel.
To get your library items to compile into the the SWC, check "export for ActionScript" and "export in frame 1", then write your fully qualified class name into the "class" field. "Base class" should be set to flash.display.MovieClip or flash.display.Sprite (for MovieClip items), or flash.display.SimpleButton (for Button items)- whichever fits the object best.
Also, note that it is customary to use camel case for class names (eg: DclUIMouse). The all caps DCL_UI_MOUSE would be used when naming a constant.