Unable to access other flas movieclip into the Action Script 3 - actionscript-3

I am creating a structure in Action Script 3 using Adobe Animate CC and there are index.fla where I am attaching document class Main.as. I am able to access all the movieclips which are created in Main.fla but I also created a other fla (mainmenu.fla) but I am unable to access movieclips into other class (Mainmenu.as) which are created in mainmenu.fla.

Export that mainmenu as an SWF file.
Then in Main project file you can load the SWF and access its variables. mainmenu.fla must be first compiled (ie: packaged) in order to be usable in another app.

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).

Do you need the linked AS files after publishing .fla into .swf in flash professional?

I want to link external ActionScript file with my current fla project file so I can get the advantage of using classes in Adobe Flash professional CS6 in ActionScript 3.0.
But I am wondering if I can delete the AS file once the fla file has been published into swf?
Or even better would be if somebody could suggest me how to create classes in Flash CS6 without creating external files.
Thanks
When you publish a SWF file - all the source code (.as class files, library objects) are embedded into the SWF. (With the exceptions of Runtime Shared Libraries or any other assets you load at runtime).
This means that your SWF is not dependent on those .as files to run.
However, if you want to be able to re-publish or edit your project, you'll definitely need those .as files for that.
In regards to FlashPro, you cannot create class files that embedded in the .fla, they have to be separate .as files. You can however edit the .as class files in FlashPro.

Referencing ActionScript file

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

How to effectively load SWF libraries?

I am making an AS3 project in FB4. In our workflow, we have artists compile art into SWC files which the I then link as 'Referenced Libraries' in FB4.
Then I set the "Link Type" of the SWC files to "external" instead of merged into code. This should create SWFs corresponding to the SWC files in the output folder, right?
This doesn't seem to be the case. I am only seeing one SWF file: the main_app's.
I was trying to make it so that I can use a library manager to load the files dynamically.
I tried extracting the swfs manually, but it seems the main_app still compiles all the swcs to itself. I made sure the Link Type was set to external. The file size for the main_app between "external" and "merged to code" seem to be the same.
I've made a simple project in Flash Builder 4 and the only way I got the SWC->SWF happening is by creating a Flex Project instead of an ActionScript Project and selecting "Runtime shared library (RSL)" instead of "External". This is because the Flex framework have some classes that work out the loading of those libraries for you. It also automate the conversion (I should say extraction) process.
Now, if you don't want to create a Flex project just for this, you can extract the SWF yourself. The SWC file format is just a Zip containing a SWF and an XML file describing the content. You can then load dynamically this extracted SWF file using a Loader and setting the correct Application Domain. Here's a snippet of my sample project.
public class Web extends Sprite
{
public function Web()
{
//you will not be able to instantiate classes of your library until it's loaded
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest("library.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
}
protected function onLoadComplete(event:Event):void
{
//here you can create instances of classes defined in your library
new Asset();
}
}
You might think that's a pretty tedious job to unzip+copy every time your designers update the library. You could automate this process with a script or an Ant file. Unfortunately, unless I'm missing something, it looks like Flash Builder doesn't want you to extend your build process, so you will still need a bit of hand work or completely convert to Ant (or something similar) to build.
Good luck!
From the moment the SWC is added to your Library, you should be able to access the SWC's assets by directly calling their specific class names . There's no need to try to get a SWF and load it with the Loader class. This actually defeats the purpose of using a SWC in the first place!
Let's say that , in your SWC, you have a MovieClip with a class name of GraphicAsset, to create a new instance , you simply do this:
var mc:MovieClip = new GraphicAsset();
In FB4's folder structure , have a look at your SWC in the Referenced Libraries folder & check the default package, you should see a list of all your assets.

How do I make a flash library that can be either compiled in or loaded at runtime?

I'm looking to make a library that can be either merged into a swf at compile time or loaded into a swf at runtime. The way I understand it, .swc files are generally merged into a swf at compile time, and .swf files are generally loaded into a swf at runtime. Is there a way I can have one file that can do both?
You could try using authortime shared libraries.
Basically you would have an FLA that has the shared animation in a MovieClip. You could build this clip separately as a SWF and use that for any files that need to load it at runtime.
Then, in any other projects that need the clip to be compiled in, you'll create a new MovieClip in that project and link it to the shared clip in the other FLA.
In the Symbol Properties, hit Browse at the bottom in the Source section and navigate to the FLA and then the shared clip. Tick 'Always update before publish'.
Now, if you make changes to shared clip, you'll recompile the SWF that gets loaded, and recompile any of the other projects that use that shared asset. They should automatically import the newest version when they get built.
What are you trying to do? What is the "library" supposed to do or provide? If it's an animation, you can drop it in the IDE and have it compiled in (as opposed to loaded at runtime). If it's code, it's nonsensical to load it at runtime.