What does "Packages cannot be nested" in AS3 mean? - actionscript-3

I got the complie error "Packages cannot be nested". What does it mean, and how do I fix it?

While you can have more than one Class, you should only have a single Package in each of your .as files. Check your .as files to see if you have more than one instance of Package.
Update based on OP's comments:
You cannot use Packages or Classes on the timeline. You need to place that code in an external file and link to it either by making it your Document Class or by assigning it to a symbol in your library via the Class property in the properties panel.

Related

Is it possible to put a Class linked to a document (aka Document Class) into a RSL and still have it as Document Class?

Firstly, my environment. My question is if it's possible to do so using Flash Professional and not Flex, FlashBuilder or the like (I don't have those environments at the moment).
Here is the thing: we have several .fla files with a Document Class set. The .as file with the class is shared with all those .fla files, so all them have this same class set as their Document Class. The point is that because of that the Class is compiled into each generated .swf files, and as result any changes made to the Class would require all the .fla files to be recompiled.
After some research I found out about RSLs. But I'd like to know if it's possible to have the class as RSL while also having it as Document Class for each file? It would ease stuff because in case a change needs to be done in the class we wouldn't need to recompile each file, or regenerate each .swf files.
Aditionally, if it's possible, how could I implement a RSL through Flash Professional? All the documentation I have found shows that through Flex and others.
Please let me know if I wasn't clear enough.
As already pointed out, you cannot use a RSL with a document class. However, you can put classes in an RSL and load those at runtime likely achieving what you desire.
Here is a very simple example:
1. Create the RSL assets:
Let's say you have a class that changes from time to time and you want to load it's functionality at runtime:
//TestyMcTestFace.as
package {
public class TestyMcTestFace {
public static function go():String{
return "I'm Testy McTestFace";
}
}
}
So, what you can do, is make a new AS3 project in FlashPro/AdobeAnimate CC. Link up your class file so your project finds it (in this case I just put my TestyMcTestFace.as in the same directory as the new .fla I created).
Put a reference in the timeline code to the class(es) you want included. Without this reference the class will not get exported in the resulting swc/swf.
So for this case, I have a new AS3 project with just one line on the first frame of the timeline:
TestyMcTestFace;
Now, go to your publish settings, and make it so only Flash (swf) and SWC are checked.
Publish this new project (you now have a swf/swc you can use as a RSL for other applications).
2. Setup your other applications to use the swf/swc as a RSL.
In your existing flash project, go to the 'Advanced Actionscript Settings' (click the wrench icon next "Actionscript 3.0" in the publish settings).
Click the library path tab, click the plus button, then click the "Browse To SWC File" button (currently it's an icon with the flash 'f' in it). Find your swc file from the previous step.
Now, with your new entry highlighted, click the info icon (linkage options). Change it from "Merged into code" to "RSL". Then add a path to the swf file (where it will be when this application runs).
Now, in your application, you can reference classes from the RSL. So if we do this:
trace(TestyMcTestFace.go());
You should get the output "I'm Testy McTestFace".
FlashPro will automatically load the RSL for you. Be aware though, that if you aren't letting flash preload your app automatically, it won't be available right away.
If you changed and re-exported the swc/swf from step one, those changes should be reflected when you run your existing swf again (no recompiling necessary).
Caveats:
Be careful with code in RSL's. It's easy to get clashing classes. As a best practice, only put code that is completely standalone/de-coupled into RSL's. Code that has lots of imports should be avoided. It's also best if you don't reference classes with same names in your compiled swf's that you are loading the RSL's.
Also keep in mind that RSL's can have sanbox/security restrictions if not coming from the same domain.
not possible, RSL is only meant for runtime sharing not for compile time sharing which you need to access the class.
First thing is, one class is not that much in term of size so there's not really a need to make it unique a sharable between swfs.
Now you affirm that all swfs would have to be recompiled if you make any change but that's not actually accurate since only one class definition can exist in one given runtime. The first swf running is by default the one loading the class definition, all the loaded swfs following would have their class definition discarded by default so no you don't have to recompile them in theory.
So to resume yes you have to recompile all swfs if you make major changes to the class but not for minor changes. But that situation is symptomatic to your app design which might not be the most efficient and logical.

Actionscript : 1087: Syntax error: extra characters found after end of program

I tried importing a .as referring to my variable name/value
import "net.chars."+adc;
You can't dynamically import a path via a string, because AS3 imports occur as compile-time. They're simply directives to tell the compiler what classes/packages you're using, nothing more.
You might be able to use the getDefinitionByName function if you really need this functionality, as described in this answer. However, you should note that you still have to reference the class somewhere in your code, otherwise it won't get compiled into the SWF. Flash has no way of loading classes externally at runtime, so you have to ensure that the compiler knows to include it.
For more information, see this article.

mxmlc load-externs is ignored

I develop an ActionScript 3 project using FlashDevelop 4.
I have a main SWF holding all the code.
I want to export some of the main SWF code into modules.
I created a module to hold the separated logic (by extending ModuleBase).
I don't want the module SWF to reference anything that is available in the main SWF so i ran the main SWF compilation with -link-report and got a report.xml file holding all the main SWF references.
I tried to compile the module (mxmlc) while excluding any class or library in the main SWF using the load-externs=report.xml option.
The compilation gave me an error saying that some libraries references are missing, but the error message referenced classes that are suppose to be included only in the main SWF.
I checked the report.xml file and it does show that these classes are referenced.
I tried to run the compilation in 3 different ways and always got the same result:
Using the build current file in FlashDevelope and giving the file a header of the command that should be ran.
Using command line (windows).
Using Ant build script.
Does anyone have any idea why this could happen?
I would be happy to supply more information about my problem if it helps anyone guide me to a solution.
Thanks for the help!
It turns out that it did not ignore the load-externs.
The load-externs excluded some of the libraries and therefor these libraries were not found during compile time.
I solved the problem by adding the libraries path to the compilation.
This was done by addind the flag: -l+=lib\

Refer to ViewNavigator in Code

I need to call navigator.pushView from an .as file in an AIR mobile project. But since I'm in an .as file and not in the .mxml file, how do I get access to the ViewNavigator?
EDIT: I don't have this set up as a tabbed navigation project; my root is ViewNavigatorApplication. I found this as a suggested solution:
parent.parentApplication.vn.pushView(MyViewClass)
But there are two problems with this. First, it assumes there's a ViewNavigator named vn. I don't see how to name the ViewNavigator, or even where it can be found. Second, I introspected the parents of my .as class and in order to get to parentApplication I would have to do:
this.parent.parent.parent.parentApplication.vn.pushView(MyViewClass);
Note that 'this' is also not the view I want to push. I just want to push a View.mxml class from my .as class.
Thanks for any insights.
You should be able to use
FlexGlobals.topLevelApplication.navigator.pushView(NewView)

Flex, ActionScript - StringUtil

I am trying to edit an already existing Flex project, and I see a warning on the line
"import com.Adobe.utils.StringUtil;" and the warning it shows is
Multiple markers at this line:
-mx
-The import utils could not be found.
-The import StringUtil could not be found.
so what could be the problem?
Well I was wondering what is the difference between import com.Adobe.utils.StringUtil; and import mx.utils.StringUtil;
com.adobe.utils.StringUtil and mx.utils.StringUtil are different classes. From the manual of mx.utils.StringUtil:
The StringUtil utility class is an all-static class with methods for working with String objects within Flex.
Mark that within Flex part.
And com.adobe.utils.StringUtil is part of Adobe's as3corelib which is a pure AS3 library and offers different methods. You need to add the as3corelib's StringUtil to remove the warning.
com.adobe.utils.StringUtil is from the as3corelib -- https://github.com/mikechambers/as3corelib
If this is not included in your project, then flex can't find it. You can either include it or change all imports to use the mx path. However, there might be a specific reason the as3corelib was included in the old project, so be aware of that.