How to import own packages in Flash Builder? - actionscript-3

I am new to Flash Builder so this is an easy question for anybody who has some experience with flash builder and actionscript 3.0.
So basically I have a folder with .as files. The directory of it is -
...\src\assets\Stadium\MyClass
Now I want to use it in my Flash Builder Project, but when I import like this -
import assets.Stadium.MyClass.PrefabProject;
There are warnings ... look in the image below.
How can I possibly use the contents of the folder in my as3 code.
How can I use the folder as a package?
EDIT: I went ahead and tried to use the stuff from the package in the code - This is the error I got -
A file found in a source-path must have the same package structure 'assets.Stadium.MyClass', as the definition's package, ''. MyClass.as /proj_away_alpha_new/src/assets/Stadium/MyClass Unknown Flex Problem

The error you have posted in your edit seems to imply that your package statement in MyClass is empty. The package statement should contain the same path that your class is in.
Since MyClass.as resides at the path (relative to your project): assets/Stadium/MyClass
The package statement (at the top of MyClass.as) should be the same:
package assets.Stadium.MyClass
I may have interpreted that error incorrectly. Just make sure that the package statement in MyClass.as is the same as the location of the class file on disk (relative to the project's src directory).
PS: The only time you use an empty package statement is when your class resides in that special "default package" (where your main app is).

Related

Compile error Flash CC 1017

Hi all I am trying to modify some flash files provided as part of a training package supplied on a DVD.
The DVD contains the final training packages as well as all the source files.
I have opened one of the source FLA files in Flash CC and fixed some typos in the text, then republished the SWF.
When republishing I get two errors.
1 Symbol 'noteBtn1' 1017: The definition of base class RolloverCursor was not found.
2 , Line 1, Column 1 5000: The class 'RolloverCursor' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
I have looked at the noteBtn1 Symbol and cannot see any script attached to it ?
I have assumed that by simply hacking the original fla file all the correct paths and setting should be inherited from the FLA file.
If I try and run the resulting SWF file it doesn't initailise correctly leaving all the assets visible simultaneously.
The FLA file has a single scene in it with the first layer being a script layer.
There is only one frame in the scene
It has been a long time since I touched Flash so a little help would be gratefully appreciated !!
Regards
Gus
There must some Action Script along with it in a folder which you probably didn't copy along. This happened to me as well a lot of times. Just search for the folder containing the 'as' file of RolloverCursor.as (most probably) and make sure it is in the same folder as your flash file.
The original object in the Flash project causing the error was not used. I have removed it from the compile. This caused another error about a missing library
The missing library was a 3rd party actionscript library. This was then downloaded and installed in the same directory as the FLA file.
Import statements updated to reflect the correct package structure, the object has now compiled.
I still cannot see how to set the global class path in the Adobe CC 2014 version of Flash professional

import interface built outside of flash

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.

AS3: How can I use TweenMax in a different package

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;

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