Archive for the ‘ActionScript’ Category

If you are interested in programming with pure ActionScript 3 code, there is a decent Open Source alternative to Flex, Flash and others. Like most products and especially open source ones, they can be a bit quirky to get started in. So here is a quick guide to get started using Flash Develop for ActionScript 3.

  1. Download the Flex 2 SDK here
  2. Extract the Flex SDK to a directory, make it something easy like C:\Actionscript\FlexSDK
  3. Download Flash Develop here They don’t have a real website. It’s a bulletin board with a topic area for releases.
  4. Open Flash Develop. Goto Tools, Installed Plugins.
  5. Choose AS3, Settings.
  6. Input the Flex 2 SDK location to match the path in step 2.
  7. When you create projects, choose “AS3″ in the Syntax menu, and it will use the settings you just set.

That’s it!
I have found a few workflows in the IDE, but for the ost part it’s a stable alternative. I’ve been able to run all of my ActionScript3 projects from Flex2 without issue.

9
Jul

A quick study of Actionscript 3.

   Posted by: admin

Here is some code to get you off the ground in Actionscript only programming, in combination with the link I previously provided.

  1. Run Flex Builder, create a new ActionScript Project. Name it whatever you like.
  2. Change the name of the .as file to Main.as
  3. Right click in the navigator window and create a new Actionscript file and name it ObjSpawn.as
  4. Paste the Code for Main and ObjSpawn.as into their respective files.
  5. Run the program.
  6. Read through the comment in the code that explains the structure and syntax.

This project is very simple, so there isn’t a lot going on to confuse you if you are picking this up for the first time.

Main.as

package
{
    import flash.display.Sprite;

    //The class name MUST be the SAME as the filename that contains it.
    public class Main extends Sprite
    {
        //The function with the same name as the class is the known as the constructor.
        //since this is the constructor for Main, it’s the first thing that runs and will control or fire off everything else.
        public function Main()
        {
            //You must declare a variable to use it.
            //If your variable is an instance of an object, then you need to instatiate that object with "new"
            var _Wall:Sprite = new Sprite;
            _Wall.graphics.lineStyle(5,0,100);
            _Wall.graphics.drawRoundRect(0,300,500,10,5,5);
            //the name attribute can be used to quickly identify an object later. You probably don’t want a lot of objects with the same name, so you may add a serialized number to a string for the name.
            _Wall.name = "_Wall";
            //everything that will be displayed MUST be added to a display container. if you do not add the following line or an equivalent to it, you will not see the object you created.
            //This can be used to your advantage because you can build and manipulate an object independatly of when you display it.
            //The order of these child objects determines the depth of the display, where the last child is at the front.
            this.addChild(_Wall);

            //the is calling the custom class I have written, which will call its constructor etc.
            var _Rect:ObjSpawn = new ObjSpawn(100,100);
            this.addChild(_Rect);
        }
    }
}

ObjSpawn.as

// ActionScript file. If you put it in the SAME directory as your main file you don’t need to define the package name, and it is automatically included with Main.
package {
    //These are the libraries required for the script. Without including the correct libraries, the compiler will simply tell you that it can’t find the data types or methods you are trying to use.
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.*;

    //everything in Actionscript 3 must be in a class. When you create a class you can extend an existing class so that it inherits all of the properties and methods of that class.
    public class ObjSpawn extends Sprite
    {
        //a private var or function can only be access by this class and its subclasses.
        //variables are defined as:  accessLevel var variableName:dataType = value;
        private var _XSpeed:int = 5;
        private var _YSpeed:int = 5;

        //a public var or function is availabel to all other classes, even if they aren’t related to this class.
        //function declaration is: accessLevel function functionName(requiredParameters)
        public function ObjSpawn(_width:int, _height:int)
        {
            this.graphics.lineStyle(1,0,100);
            this.graphics.beginFill(0xFF8800);
            this.graphics.drawRoundRect(_width,_height,10,10,0,0);

            //event listeners assign a function to an event. since the event listener is defined inside the class it only applies to this class.
            this.addEventListener(MouseEvent.CLICK, onMouseClick);
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        //function used for the enterframe event for this class.
        //this fires as many times a seconds as is running on the client, so you may ant to standardize the framerate programmatically.
        private function onEnterFrame(event:Event):void
        {
            //action that looks at X and Y hits separately.
            /*
            if (this.x >= stage.width || this.x < 0)
            {
                _XSpeed = -_XSpeed;
            }

            if (this.y >= stage.height || this.y < 0)
            {
                _YSpeed = -_YSpeed;
            }
            */

            //This looks for a basic collision of 2 objects and takes action.
            if(this.hitTestObject(parent.getChildByName("_Wall")))
            {
                _XSpeed = -_XSpeed;
                _YSpeed = -_YSpeed;
            }
            //call to the movit function.
            this.moveIt();
        }

        private function onMouseClick(evt:MouseEvent):void
        {
            var _Rect:ObjSpawn = new ObjSpawn(0,0);
            this.addChild(_Rect);
        }

        //accepts direction and speed for moving the object. The effect gained from moving a # of pixels on the enter frame event is simple animation.
        private function moveIt():void
        {
            this.x += _XSpeed;
            this.y += _YSpeed;
            //this.rotation += _XSpeed;
        }
    }
}

28
Jun

Diving into Action Script, again.

   Posted by: admin

With the introduction of Actionscript 3.0 I’m going to try to implement some ideas that wouldn’t have performed as well in Actionscript 2.0. Also, now that Actionscript has matured to the point where I’m more familiar with the syntax and methodologies I’m more comfortable in approaching it. I’m much more comfortable with code than the flash interface and timeline.

Here are some links that are both very inspiring and helpful:

This has many examples of element interaction and physics. Each example is segmented so that it’s not complicated by too many things occuring at once, and source code is provided for all of them.
 http://www.entropyswitch.com/3_00.html

This is a physics engine written in ActionScript 3.0, the performance seems very good, and it has a lot of features. This could serve as a basis for collisions, attraction, repulsion, gravity etc.
http://www.fisixengine.com/engine.asp

This is the most impressive display of creative skill applied to flash I’ve seen yet. This guy gives out his source on any of his projects, all of his projects are worth looking at for inspiration and ideas. This guy definately belongs in the “Master” class of Actionscript developers.
http://lab.andre-michelle.com/

This is a project in SourceForge I found where they allow you an interface to draw on a web canvas and then it saves all of the ActionScript code so you can copy and paste it into your apps. This is a great tool for those who don’t care for the Flash IDE and timeline! http://musprite.sourceforge.net/

Here is a blog for someone who wrote and AS3 animation system for others to use. His blog also well done. http://www.boostworthy.com/blog/?p=171

A VERY impressive 3D engine for AS3. http://blog.papervision3d.org/

I’ve decided to use Flex Builder to write my “Actionscript projects” so that I have more of a development interface than the Flash one.
http://www.adobe.com/products/flex/flexbuilder/

 But FlexBuilder does cost some $$ so you may want to check out FlashDevelop: http://www.flashdevelop.org/community/

No matter what IDE you use, you’ll need the languag reference: http://livedocs.adobe.com/specs/actionscript/3/wwhelp/wwhimpl/js/html/wwhelp.htm

Another Extension Library, when the existing language isn’t enough: http://www.senocular.com/flash/actionscript.php

Nice blog I found on Actionscripting http://www.actionscriptarchitect.com/
Good luck on your projects! I’ll be posting mine on this page.

More amazing work: http://levitated.net/daily/index.html