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.
Related
Is it possible to play a sound from the library by its name and not Class Linkage in actionscript3?? Meaning if I have a sound named "mysound.mp3" in library and does not have a linkage name, can I play it dynamically in my code by any means?? I hope my question is clear.
In general it's not possible, because if you don't use your sound in some timeline it will not even be exported to swf.
If you are using it in timeline (so it's exported to swf) it's possible to extract it in run-time with some third-party libraries/as3 decompilers by parsing raw swf bytes, but I don't advice to go with that way - it's not stable and system resources consuming.
It's much more easy to set linkage, btw why you don't want to do that?
If you want to create an instance of a Class dynamically, you must call it by its AS Linkage. Why proceed in any other way?
How to proceed?
Right-click the sound file in your library and make it available for ActionScript by editing its Linkage properties: select Linkage to open up the linkage window > ActionScript > ActionScript Linkage : MySound (select Export for ActionScript and Export in frame 1). That will export your sound file as an ActionScript Class called MySound.
You can also select Linkage from the Library Panel menu and create or modify your AS Linkage:
So you can create a new instance of your sound Class and play it:
var s:MySound = new MySound();
s.play();
Trying to learn from a game on github which is backgammon and the fla stage is empty with class files external so when you test the swf it cannot find the interface that is attempting to load :
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import multiflame.game.IGame;
import multiflame.game.IContainer;
import multiflame.game.Constants;
Would the interface be something created in flash builder which I use along with flash CS6 or could those AS3 files be just as easily created in flash? I am new to flash builder and trying to figure out if it is used primarily for networking builds in which case the interface would be best executed there or doesn't it matter?
For very basic explanation - in your case interfaces are very similar to classes - external files with code in it. They are nothing special created with different programs - they are just plain text files named .as
You should provide the error you're getting, but if it says that the interface cannot be loaded, it means that Flash cannot find the file. In your case, if the interface error is about IGame, it means that in your folder where the .swf file is, you must have subfolder multiflame with game folder inside it, and a IGame.as file there.
This is of course if you don't know how to manage source paths - there's a property inside Flash AS options which you can set to target specific directory (for example D:\ can be mapped as root of your classes and so multiflame directory should be inside D:\, no matter where your swf is).
p.s.
Further you can read about interfaces and what they do: http://code.tutsplus.com/tutorials/as3-101-oop-introduction-to-interfaces--active-8199
I haven't read the whole tutorial but it seems large enough to cover the idea.
So I'm trying to build a separate package. In that package I would like to reference TweenMax, however I'm having trouble linking to it (error Definition com.greensock:TweenMax could not be found).
Here is my dir structure:
myApp
--com
----greensock
------Tweenmax etc
----myPackage
------packageClass.as
--------elements
----------elementClass.as (this is the one trying to access tweenmax)
--src
----Main.as
main.as is the document class, just so I can test myPackage. Doesn't do anything except instantiate myPackageClass and stick it in the displayList.
In the elementClass.as I have:
import com.greensock.TweenMax;
which flashDevelop seems to see within the ide, but when I compile I get the ...could not be found error.
So how can I reference tweenmax from my elementClass file (I have src and com dirs in the classpaths.
I'm using flashDevelop with flash player 11.7 and Flex 4.6.0 SDK.
Am I going about this all wrong?
I'm going to ask the hopefully obvious question, did you import the greensock folder?
import com.greensock.TweenMax
Ok let's say you did that already. Maybe you need to tell your code where your libraries are. Go to File > ActionScript Settings, or, on the stage's property panel, click the wrench icon next to the Script drop down menu.
You should see a dialog with three tabs, the first two of which are labeled Source path and Library Path. Forget about the third.
In the Source path tab, you should at least have a dot - (.) - as one of the choices. That tells flash to look for any actionscript classes it can't find at compile time in the same directory as the source FLA. From there you can list any number of other library paths that contain supporting files.
The second tab is for SWC files. If you have a SWC library, you can tell your FLA where to find it by pathing to it here, just as you pathed to your libraries in the Source path tab.
The images below presume that there is a folder, in the same directory as the source FLA, named library. In this folder are sub folders named src and swc. Inside src are sub folders containing the greensock and facebookAPI com folders, (the latter used here for example). Inside the swc folder there is a SWC named exampleSWC.swc.
The paths shown in the pics below would allow the FLA to see the following imports:
import com.greensock.TweenMax;
import com.facebook.someFacebookAPIClass;
import com.somePackageInTheSWC.someClassFromExampleSWC;
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.
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.