Is it possible to create a flash movie from only actionscript? - actionscript-3

Currently I am mostly a PHP/Javascript/CSS/HTML applications programmer. But I would like to start learning how to create flash movies also. However, I do not want to spend the money to get CS4. Can I create flash movies from only Actionscript 3? Or would anyone recommend that I jump straight to air? All of the different adobe products, which do the same thing, confuse me.
I just do not want to jump into it and then find out that I have to spend 900 dollars for the IDE. I really just want to code, and not have to use the IDE.
Thanks,
Metropolis

Yes, you can create .swf files using only ActionScript if you use the Adobe's free Flex SDK. Even though it's the Flex compiler, it can be used to compile pure ActionScript programs.
Flex is an advanced UI toolkit built on top of Flash, which makes it easier to build applications with complex user interfaces in Flash. Flex applications are written in ActionScript and a HTML-like XML format (which is actually converted into ActionScript by the compiler behind-the-scenes). AIR is a platform that allows you to build standalone Flex applications that run outside of a web browser. I've never looked into if you an make a pure ActionScript AIR application, but my guess is no.
Here's an example of a hello world program in pure ActionScript. Save it in a file called Test.as and compile with the command line mxmlc Test.as.
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Test extends Sprite {
public function Test():void {
var tf:TextField = new TextField();
tf.text = "Hello, world";
addChild(tf);
}
}
}
FlashDevelop is an IDE for the Flex SDK. You still need to install the Flex SDK in order to use it.

I advise you to look at the Haxe community.
Haxe is a language & compiler that can do a lot of things. It is fully open source and you can create .swf files with it without the need for CS4.
The community is driven by the author or MTASC which was the first open source ActionScript2 compiler.
Haxe is now fully compatible with AS3 & Flex I believe.
check http://haxe.org/
I Hope this will help
Jerome Wagner

Use FlashDevelop :)
Here's the same code as tmdean's entered in Main.as when you create a new AS3 project in FlashDevelop.
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var tf:TextField = new TextField();
tf.text = "Hello, world";
addChild(tf);
}
}
}
You do need a Java 1.6 JRE to compile with the Flex SDK and an Adobe Flash Player (Debugger version) to view your compiled SWF file (get the one that says Windows Flash Player 10 Projector content debugger if you're running Windows).
Details on the configuring FlashDevelop for AS3 development can be found at the FlashDevelop wiki.

Related

ActionScript Library Project vs. Flex Library Project

I've got couple of issues from the nature of inconsistency between FlexLib Project and AS3 Lib Project in Flash Builder 4.7, AIR SDK 15, 16 and 17, Flex SDK 4.6.
Common thing for these is that FlexLib does not allow (syntax error highlighted) to build/compile pieces of code that are allowed in regular AS3Lib Project.
Please note that examples bellow are simplified, and there are real life use cases even if it's against good practices.
Internal classes above package
internal class Before
{
public function Before(){}
}
package
{
public class Main
{
public function Main()
{
}
}
}
In Flex Library Project this code causes:
1083: Syntax error: package is unexpected.
In regular ActionScript Library project it works perfectly fine, without a single warning.
Array key type greediness
var array:Array = [Boolean, Number, XML];
for(var c:Class in array)
{
if(c is Object) { trace('test') }
}
In Flex Library Project this code causes:
1067: Implicit coercion of a value of type String to an unrelated type
Class.
In regular ActionScript Library project it works perfectly fine, without a single warning.
Constant defined class
public static const FileClass:Class = String;
public function main():void
{
if('test' is Vector.<FileClass>)
{
trace('what?');
}
}
In Flex Library Project this code causes:
1120: Access of undefined property FileClass.
In regular ActionScript Library project it works perfectly fine, without a single warning.
I'd be very thankful if someone could say a word why is this happening or could give me a clue where to look for solution.
According to this, there are two different compilers involved:
Use Legacy Compiler
For ActionScript projects, Flash Builder uses the ActionScript Compiler (ASC) by default. If you are using Adobe Flex SDK 4.6 or an earlier version of the Flex SDK, select Use Legacy Compiler to use the older compiler.
I guess that explains the difference.
The following is an attempt to work around the problem.
I'm not too much into library projects.
From what I found in resources (the link above), these projects result in a .swc file.
I'm not too much into flex either.
Flex is "just" a framework written in actionscript.
Whether your library is an actionscript library or a flex library is not really a choice of the user, but what your code does.
If your library includes some flex components, I'd say it's a flex library project.
But if it is plain old actionscript, it is an actionscript library.
Let's say your library is an actionscript library.
You compile your library into an .swc file and be done with it.
Your are the one doing that compilation step, not the user of your library. I don't think it's their concern if they could perform this compilation.
What actually concerns them is whether their project that includes your library (the .swc file) compiles. And I guess that this will be the case, because the .swc will be used, not compiled.
After all, there's no choice to be made, if it is an actionscript library, because every flex project is an actionscript project. (but every actionscript project is a flex project)
Build your library project (whatever compiler works) and see if you can use the resulting .swc file in both an actionscript and a flex project.

Static function in base class not wanting to call member functions on subclasses if using Flash Builder 4.7, instead of 4.6

Since yesterday, I've been trying to port an ActionScript Mobile project from Flash Builder 4.6 to Flash Builder 4.7, and I've run into a little bit of a problem that's probably a compiler bug. In FB 4.6, this works:
Temp.as:
package
{
import flash.display.Sprite;
public class Temp extends Sprite
{
public function Temp()
{
new StartMenu();
}
}
}
Screen1.as:
package
{
import flash.display.*;
internal class Screen1 extends Sprite
{
private static var m_vScreens:Vector.<Screen1> = new Vector.<Screen1>();
public function Screen1()
{
m_vScreens.push(this);
onScreenSizeDetermined();return;
var strFunction:String = "useSmallPortraitLayout";
for each (var screen:Screen1 in m_vScreens)
{
trace(1)
screen[strFunction]();
}
}
protected function useSmallPortraitLayout():void
{
}
private static function onScreenSizeDetermined():void
{
var strFunction:String = "useSmallPortraitLayout";
for each (var screen:Screen1 in m_vScreens)
{
trace(2)
screen[strFunction](); // Error thrown here in 4.7.
}
}
}
}
StartMenu.as:
package
{
public final class StartMenu extends Screen1
{
override protected function useSmallPortraitLayout():void
{
}
}
}
But in 4.7, it doesn't work. The error I get back is this:
ReferenceError: Error #1069: Property useSmallPortraitLayout not found on StartMenu and
there is no default value.
Now that being said, this can be fixed in one of at least two ways:
Use Flash Builder 4.6
Comment out onScreenSizeDetermined();return;, thereby using a member function to call useSmallPortraitLayout(), instead of a static function. This doesn't require using the constructor; it works just fine, as long as Screen1 is calling useSmallPortraitLayout() from pretty much any non-static method.
Unfortunately the static method will fail, even when it's called from outside the constructor and/or from a timed delay. One thing I don't specifically remember in 4.6, but I am seeing it in at least 4.7, is that using an unrelated class to call a static method directly through an instance won't compile - it has to be done in a staticky way in unrelated classes. Not that I do things like that in real code, but it does make me wonder if the relationship between static and non-static has intentionally changed.
This is probably just some trivial compiler bug specific to FB 4.7, and I would just go right back to 4.6, but pure ActionScript library projects are directly supported only in 4.7. (This is a mobile project, but I was going to add a library project to the solution.)
One thing to note is the code will not compile in FB 4.7 if the static function calls useSmallPortraitLayout this way:
screen.useSmallPortraitLayout();
It has to call it dynamically for it to even compile.
Is there an easy-enough fix for this? Has there been a little bit of syntactical weirdness that 4.6 has simply been overlooking this whole time? What's wrong, and what's a good solution/work-around?
UPDATE
If worst comes to worst, it does seem to work to partially replace the Vector.<Screen1> with a Vector.<Function>, and then just make calls to the members of the function vector, instead of to functions of the members of the Screen1 vector. (This is simplified from production code.) But that's just a fallback.
Also, something I wasn't paying a lot of attention to previously (specifically as far as this one problem goes), but BotMaster kind of brought it to my attention, is that in the process of going from FB 4.6 to FB 4.7, I also went from AIR 3.1 to AIR 3.4.
This is more a scope issue imo. Protected method can only be called within the instance scope and not within a static scope. Of course changing the modifier to public fixes the issue here. PO might argue that protected is wanted here but in reality if there is intention of directly calling a method on an instance outside the scope of that instance then logically that method needs to be public.
Btw FB 4.6 compiler is provided by the used AIR/FLEX SDK and so cannot behave differently from FB 4.7 using the same SDK.
Flash Builder 4.7 uses ASC 2.0 to compile ActionScript projects. From the release notes, emphasis added:
ASC 2.0 is a new compiler for ActionScript® 3.0 (AS3). It has stricter
adherence to the AS3 language specification, includes compilation
performance improvements, is more stable under memory pressure, and
contains some demonstration optimizations that can be optionally
enabled (in-lining, dead code elimination).
I suspect that the compiler sees useSmallPortraitLayout() is not referenced in your original code, and is eliminated from the ABC output.

Issue Using Flex SDK in Flash Professional (for as3corelib)

I recently found Mike Chambers' as3corelib when looking for ways to render the stage to a file. Works great in my ActionScript 3.0 project in Flash Professional (CS6 if it matters).
I decided to look at some of Mike's utility classes, notably the date related ones. However, his DateUtil class imports mx.formatters.DateBase, and when I attempt to use some of the methods, I'm getting lots (and lots) of "Access of undefined property DateBase."
I'm assuming that's because some reference to the Flex SDK is missing or wrong. I've added $(FlexSDK)/frameworks/libs/flex.swc to my project's Library path, but that's not helping.
I've used Flash for years, but this is my first truly code-centric project, and still learning through the school of hard knocks. No idea what's going wrong here. Ideas?
Example from as3corelib
package com.adobe.utils
{
import mx.formatters.DateBase;
/**
* Class that contains static utility methods for manipulating and working
* with Dates.
*/
public class DateUtil
{
/**
* Returns a date string formatted according to RFC822.
*/
public static function toRFC822(d:Date):String
{
var date:Number = d.getUTCDate();
var hours:Number = d.getUTCHours();
var minutes:Number = d.getUTCMinutes();
var seconds:Number = d.getUTCSeconds();
var sb:String = new String();
sb += DateBase.dayNamesShort[d.getUTCDay()];
sb += ", ";
...
The line:
sb += DateBase.dayNamesShort[d.getUTCDay()];
...generates the mentioned error, as does any other DateBase reference in the class. Again, this code is directly from the latest as3corelib, located on GitHub: https://github.com/mikechambers/as3corelib
Don't know whether you got this one licked or not, but I hit the same thing. Love the library, hate the error messages.
I downloaded the Flex SDK from here:
Adobe Flex SDK Download
Then, I unzipped that into a temporary folder.
Then, since I didn't want the whole flex framework lurking about, I created a ./lib directory inside the directory where the .fla file lives. I then moved these swcs from here (Inside the unzipped file structure):
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/framework.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/core.swc ./lib
mv ~/Downloads/flex_sdk_4.6/frameworks/libs/mx/mx.swc ./lib
Not sure why all three were required, but it stopped the compiler complaining (and got the date conversions working).
You need to add them to the .fla's library list as well (under ActionScript Settings); but I'm betting you already knew that.
Perhaps useful, perhaps not.

AIR iOS app hangs when clicking button inside imported swf

Been bangin my head against a wall all day, thought I'd see if anyone can shed some light on this -
I have an iOS air app that imports a remote swf. Once imported, an event listener is added to a button inside the imported swf. Clicking the button causes the app to hang. Here's some code -
private function loadRemoteSWF():void{
var urlRequest:URLRequest = new URLRequest("http://www.domain.com/remote.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(urlRequest);
}
private function onLoaded(e:Event):void{
var loaderInfo:LoaderInfo = e.currentTarget as LoaderInfo;
var adPanel:MovieClip = loaderInfo.content as MovieClip;
adPanel.continueButton.addEventListener(TouchEvent.TOUCH_BEGIN, onContinueClicked);
addChild(adPanel)
}
private function onContinueClicked(e:TouchEvent):void{
trace("onContinueClicked");
}
I'm using Flash Builder 4.7 AIR SDK 3.5 ASC 2.0.
This only happens on a release build, debug builds work fine so near impossible to find the cause. It also works fine when using the legacy compiler on the same SDK version.
Dispatching a touch event programatically on the button also works fine. (thought I could do a try/catch to find an error)
adPanel.continueButton.dispatchEvent(new TouchEvent(TouchEvent.TOUCH_BEGIN));
Touching the button just kills the app, it doesn't even hit the trace.
Anyone got any ideas how to debug this, or why this problem might be happening?
Thanks
Dave
can you do a test: instead of using the the native loader, try using an API, like greensocks api - SWFLoader.
Also, try setting the accepted domains through the security class prior to loading the swf file:
import flash.system.Security;
public class Main extends MovieClip{
public function Main(){
Security.allowDomain("*");
}
}
I would suggest trying to compile with the same setup on a different machine, just to make sure that the Builder install doesn't have some issues.
Also, have you tried on different devices, (could be an issue with the device you are using)?

Flash saves in Windows, not in Linux, FileReference.save()

The code below compiles fine on the Flex 4 SDK on Fedora 15. Mouse-click opens the dialog box, I click okay, and a file is saved, but the file is empty. I run the same SWF file (that was compiled on the Linux machine) on a Windows machine, and the created file contains the expected data.
Then I broke the FileReference declaration out of the function into the class level, hoping to avoid a known bug, but the same problem persists.
Hoping to set up a workaround, I added the debug Flash player to my path and ran the file from Flash without the benefit of the browser, and it works. So now a Flex problem has become a Firefox problem, maybe owing to a shady procedure I used to install the plugin without really understanding what was happening. I am running Firefox 5.0.
In essence my workflow is fixed, but perhaps people who performed the above will not be able to use projects with FileReference.save()? Should I be worried about this edge case?
/*
WriteTheFile.as
Original code by Brian Hodge (brian#hodgedev.com)
Test to see if ActionScript/Flash can write files
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
public class WriteTheFile extends Sprite
{
private var _xml:String;
private var fr:FileReference;
public function WriteTheFile():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
}
private function _onMouseDown(e:MouseEvent):void
{
fr = new FileReference()
fr.save("<xml><test>data</test></xml>", "filename.txt");
}
}
}
EDIT: was missing a line, fixed above
EDIT: addressed answer in code above, but the same problem exists.
EDIT: This works on the same system when the standalone player is invoked. Therefore this is a browser (FF 5.0) plugin problem.
Try putting the line
var fr:FileReference = new FileReference();
at class level (outside the function). Apparently this is a known bug:
http://www.techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/