Intellij IDEA and Flex SDK runtime shared library - actionscript-3

I am trying to make IntelliJ IDEA 12 configure rsl libraries for runtime loading.
Do you have any experience with that, and do you maybe have a sample XML you put into aditional compiler options?
Also, I didnt find the plugin for this, if you know any please say
update:
To clarify the practice project more:
I want to make 2 'swf's that will have one tweening library used on a simple shape, but I want to make that tweening library crossdomain rsl.
Then the goal is to in MainApp load and add to stage one swf and then the other. What I expect to happen is that the first time rsl will be loaded and the second time it will be used from cache.
I am programing in pure AS3. Examples would be wonderful :)
Right now I am trying to build one class that has RedSquare and tweening applied to that square. Ofcourse, tweening should come from rsl library.
Update 2:
I got to the point where I create [Frame(factoryClass='path.to.class')] and I create Preloader.
But here now I dont know how to make a preloader that would load rsl's and then go to the next frame, or main class. What [Frame] tag does, is it makes two frames, one for preloader, and one for main class that should be executed after.
Config I pass to the compiler:
<flex-config>
<!-- A list of runtime shared library URLs to be loaded before applications start. -->
<!-- GreenSock -->
<runtime-shared-library-path>
<path-element>/Users/matej/Documents/Projects/Work/External/greensock-as3/greensock.swc</path-element>
<rsl-url>http://localhost/~matej/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/~matej/rsls/crossdomain.xml</policy-file-url>
<rsl-url>http://localhost/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/rsls/crossdomain.xml</policy-file-url>
</runtime-shared-library-path>
<!-- static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.-->
<static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
</flex-config>
main class
package {
import com.greensock.TweenLite;
import Preloader;
import flash.display.Sprite;
import flash.events.MouseEvent;
[Frame(factoryClass="Preloader")]
public class RedSquare extends Sprite{
//---------------------------------------------------------------
// Private variables
//---------------------------------------------------------------
private var redRectangle:Sprite;
//---------------------------------------------------------------
// Constructor
//---------------------------------------------------------------
public function RedSquare() {
redRectangle = new Sprite();
redRectangle.graphics.beginFill(0xFFFF0000);
redRectangle.graphics.drawRect(100,100,50,30);
redRectangle.graphics.endFill();
addChild(redRectangle);
redRectangle.addEventListener(MouseEvent.MOUSE_OVER,onOver);
}
//---------------------------------------------------------------
// Public methods
//---------------------------------------------------------------
//---------------------------------------------------------------
// Private methods
//---------------------------------------------------------------
private function onOver(event:MouseEvent):void {
TweenLite.to(redRectangle,3,{x:400,y:200,rotation:160})
}
}
}

Related

Actionscript3 Main class is the root, but does not allow the Animate Virtual Camera

I've recently started learning Animate CC with Actionscript 3.
I'm trying to use Animate's "Virtual Camera" feature, giving me a camera that can pan, rotate, and zoom the game.
It's easy to implement a Camera when the root has no subclass. For example, you can put a block on screen, and add a camera effect within the timeline itself, and play your movie it. Easy.
But when I give the fla a class ("Main") and give that class an external AS3 file, I get an error:
Specific image showcasing what I mean about giving FLA a class
The code below is "Main.as"
package {
import flash.display.MovieClip;
import flash.display.DisplayObject;
import fl.VirtualCamera;
public class Main extends MovieClip {
var camera;
public function Main() {
// constructor code
camera = VirtualCamera.getCamera(root);
trace(camera);
}
}
}
Now, even when I had absolutely no code (other than functional necessities) in Main.as, and a Camera in the timeline, I would get this error:
ReferenceError: Error #1069: Property ___layerDepthEnabled___ not found on Main and there is no default value.
at privatePkg::___Camera___/cameraControl()
I added in this code above to Main, and I get the same error.
The only thing that fixes it is changing
camera = VirtualCamera.getCamera(root);
to:
camera = VirtualCamera.getCamera(this.parent);
and that, while eliminating the code, also doesn't actually give me a camera to use.
How can I use a Virtual Camera and still have Main.as?
Thanks,
Andy
Try declaring public dynamic class Main because it is not impossible that VirtualCamera class is expecting a generic MovieClip as root (which is dynamic = you can add any property without raising an exception).

How do I add MovieClips to the stage while using AIR?

So I had been messing around in AS3 for awhile and had done some basic starting flash game things, but then found out I could use air to make them for mobile platforms. So I tried copying over what I had worked on before, but I am running into issues.
Right now I am just trying to find out how to add an instance of a MovieClip to the stage. I have an image converted to a MovieClip with it's own class so I can manipulate it later (such as moving around) and I have this in my Main class:
class Main extends MovieClip
{
var space:Background; //Background is the MovieClip
function Main():void
{
space = new Background(stage);
stage.addChild(space);
}
}
But when I run the program, the image doesn't show up. It works that way when I just had a standard AS3 program and I don't understand why it would be different when I am trying to use AIR. Any assistance would be greatly appreciated, thank you.
Put the word 'public' in front of 'class' in your first line.
Also remove the 'stage' from the first line in your constructor: make it space = new Background();
And do you really need 'stage' in the addChild statement? Unnecessarily verbose!
I can run this code through the AIR compiler (AIR SDK 3.8 or later):
package
{
import flash.display.MovieClip;
public class MAIN extends MovieClip
{
var space:Background;
public function MAIN()
{
space = new Background();
stage.addChild(space);
}
}
}
With an image inside the Background class it shows up fine. My 'Background' is a library symbol linked for Actionscript. If your 'Background' is pure Actionscript are you adding a graphic to it?
Rajneesh Gaikwad had the answer, I didn't have my Main class as my Document class.

Action script adding a background

First of all I've just a couple hours experience with Flash and AS3 therefore, I'm sorry if it is a bit easy question.
What I want do to is a simple space war games to learn basics of AS3 and flash. Altough I dont know much things about layers, I think my game should contain two layers, one for background and the second one is for enemies spaceships and our spaceship.
I added a jpeg format file to library to use it as a background. (as you can see from the link :http://prntscr.com/2pe6zb and http://prntscr.com/2pe733 )
And I create a as3 documentFile which is called Arkaplan.as and content of it is:
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var hero:backGround =new backGround();
addChild(hero);
}
}
}
However, I got an error which says that : "1180: Call to a possibly undefined method BackGround."
Is there anyone to help me to solve what is wrong ?
EDIT
When I changed the code above lilke :
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var myBitmap:Bitmap = new Bitmap(new backGround(500, 500));
var myMovieclip:MovieClip=new MovieClip();
myMovieclip.addChild(myBitmap);
addChild(myMovieclip);
trace("deneme 1-2");
}
}
}
Problem is solved but I dont know why it runs correctly know ? To be able to use Bitmap Do I have to add it as a child to movieClip ?
Any time you use the word 'new' you are creating a new object. The word after new will be the name of a Class that Flash will try to locate. You must either have an external .as file that matches that name or have a library item set to 'export for ActionScript' with a Class name that matches that name.
You can access a library item's properties by right-clicking on it in the library and clicking 'properties'. With the 'advanced' option open, check the 'export for ActionScript' box and enter a Class name that matches the one you want to create.

Using a separate .fla file as a MovieClip in a larger project

Just to preface: I haven't used Flash in a long long time, however, I am still aware of the environment.
Backstory: I created a small .fla to perform actions on a MovieClip on the stage (in my case, a health/HP bar). I made the health effect using a Document Class (HealthBar.as).
The question: What I'm trying to figure out now is how, in a totally separate .fla, to create multiple instances of these health bars and be able to access the methods in Document Class HealthBar.as from the Document Class in this new .fla
If I am doing this incorrectly in the first place, feel free to yell at me, and let me know how doing something like this SHOULD have been done.
Thanks for any help
You're halfway there with a document class. Now you just need to make it into a proper class in your com.domain.className (or drop the .as file into the same directory as your fla). While creating classfiles is trivial, online examples seem to muck it up, so here's Adobe's official demo (bleh).
That said, creating more healthbars basically looks like this...
Class
package {
public class HealthBar extends Sprite {
public function HealthBar() {
// constructor
trace("Healthbar created")
}
}
}
Document Code
import HealthBar;
for (var i:int = 0; i < 10; i++) {
var randomHealthBar:HealthBar = new HealthBar(); // <-- magic sauce
addChild(randomHealthBar);
}
// traces: "Healthbar created" 10 times
Shouldn't you be able to copy the movieclip from the healthbar .fla into your main .fla and then give it an actionscript linkage of HealthBar?
Then you should be able to call new HealthBar whenever you need one in your main file.

ActionScript Frame metadata not working

I know there exist a lot of posts about the Frame metadata tag in ActionScript,
but I still didn't find an answer to my question.
The problem is, I have specified a Frame metadata tag above my Main class header:
package gameUI {
...
[Frame(factoryClass="gameUI.MyPreloader")]
public class Main extends Sprite {
public function Main()
{
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{ ...
I also have a preloader class in the same package (gameUI) called MyPreloader.as
package gameUI
{
// imports..
public class MyPreloader extends MovieClip
{
// private vars ..
public function MyPreloader()
{
trace('preloader START');
...
In my IDE, i don't get any errors or warnings. It compiles without problems.
But when I run it, it just skips over the Frame meta tag and just runs the code of the Main class. (The trace in the constructor of MyPreloader is never printed out).
I'm thinking maybe it has something to do with some arguments specified in the compiler settings. I've tried some couple of things, aditional compiler arguments but it never worked.
Does anyone know why he ignores the Frame metatag?
I'm really frustrated right now..
I'm using Flash Builder 4.6.
Compiling with Flex SDK 4.6.
thanks.
Your Main Class is a Sprite, so it can't have two frames. That may be part of your problem.
However, it might be that you can use a process that's easier to debug to accomplish the ultimate goal. For example, this is one approach. I personally usually just set my default export frame as 10, put a spinner on frame 1 and issue a play().
The only assets that need to be compiled on Frame 1 are in the spinner. It will then pause while the spinner spins and the assets load (because it has to load everything compiled there before it can proceed). Once all the assets have loaded, it will naturally advance to Frame 10. I will have an instance on the timeline at Frame 10 that has an associated getter and setter, so when the setter triggers, I know that loading is complete.
I only check "Export in Frame 10" for assets that absolutely have to be loaded at startup (for example, sounds or visual objects that are never used on the timeline).
The advantage of this approach is that you can get to the real content earlier (because only assets compiled on your default frame have to load before you can show anything), but the disadvantage is that it makes no sense to show % progress, since you have no idea what percent of the movie is compiled on frame 10 and needs to load before it will start.
So, in summary:
Try making the Base Class for your fla a MovieClip
If that doesn't work, consider changing approach