Nov 6

I’ve bookmarked this site. You should too! There are some very useful and helpful tips in there. Like the latest one, as of this writing, about simplifying multiple method calls to a graphic (or any) object.

From this:

mc.graphics.lineStyle(0);
mc.graphics.moveTo(10, 10);
mc.graphics.lineTo(20,10);
//...

To this:

with (mc.graphics) {
    lineStyle(0);
    moveTo(10, 10);
    lineTo(20,10);
    //...
}

Much more readable and easier to type. :)

Check it out here and bookmark it.


Oct 30

I found this little class that displays the framerate of the current movie and the total memory usage of the Flash Player on your movie. It also shows the version of the player and the operating system you are on. It even has a graph. Very useful for monitoring your experiments or whatever. 

Link.

If anyone knows something better, please let me know. 


Jun 5

Here is another class I made for my site… It’s nothing fancy, and in fact it could easily be done without this class, but basically, this class creates a rectangular object and fills it with an image from an outside source, tiles it, and you could easily adjust the width and height of the object, and load a new pattern.
Usage:

import com.mindfock.display.TiledBG; //import class
...
tiledBG = new TiledBG("path/to/pattern.gif", 800, 600);
addChild(tiledBG);

tiledBG.tileWidth = 500 // change width
tiledBG.tileHeight = 500 // change height

tiledBG.newPattern("path/to/new/pattern.gif"); //changing pattern image

Download here.


May 14

It’s been a while since my last post. My connection has been down for a few days, so I haven’t got the chance to post. But during this downtime, I found some time to create some experiments in Flash/AS3.0 (maybe I’ll post it soon). I needed to call a method at timed intervals in this one experiment, and I thought I was in trouble. I never got around to getting how AS2.0 handled timers, if I did manage to do timers, they end up dirty.

AS3.0 has a much much better Timer class to handle just such events. Now, I’m not going to bother comparing the AS3 Timer class with AS2’s timer handling, I’m just going to give a quick intro to the class.

First, you need to create a new Timer object. The constructor has 2 parameters, delay and repeatCount. delay is the time in milliseconds the intervals will be. repeatCount is the number of times the Timer will run, assigning it 0 will set it to run infinitely.

var myTimer:Timer = new Timer(1000, 5);

Now, we want to write a function that will get called when an interval is passed (every 1 second), and when the whole timer finishes counting (after 5 seconds). The Timer class dispatches two events, TimerEvent.TIMER is dispatched when an interval is passed, TimerEvent.TIMER_COMPLETE is dispatched when the timer is finished (I love how simple that is).

stage.addEventListener(TimerEvent.TIMER, everySecond);
stage.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);

function everySecond(e:TimerEvent):void{
    trace("tick tock!");
}
function onComplete(e:TimerEvent):void{
    trace("Timer finished!");
}

Now, we just need to start the timer. The Timer class has 3 methods, start, stop, and reset. Those are fairly self-explanatory. We could now add the following lines:

myTimer.start();
//modify the onComplete function
function onComplete(e:TimerEvent):void{
    trace("Timer finished!");
    myTimer.reset();
    myTimer.start();
}

So now, when our timer finishes, it will automatically start all over again. This will trace

tick tock!
tick tock!
tick tock!
tick tock!
tick tock!
Timer finished!
tick tock!
tick tock!
...

This was just a really quick intro to the Timer class, I just felt like sharing this because I was so relieved at how easy it was to handle timed events now.


Apr 26

Adobe’s ActionScript online docs that is. This has got to be the best resource you will ever find if you have trouble with ActionScript. I only found that out myself yesterday. I always thought that the online docs, or any other documentation/reference/manual, were scary to look at. Just the sight of all those complicated words that don’t seem to mesh together terrifies me. But when I was bored the other day, I decided to just read up on the BitmapData class just for kicks, and as I was reading, I surprisingly understood everything I read! I have never used the BitmapData class before, but I think I’ll be doing a lot of experiments with it soon (I have seen what others could do with it).

It has been laid out so well, everything is explained thouroughly, with simple and understandable examples and it’s searchable. It’s basically one giant tutorial about ActionScript! If there is one, I would love to buy a print/book of the online docs, because I hate reading on the monitor for extended periods of time. And yes, I’ll be reading the online docs for extended periods of time. ;-)


Apr 23

I was just getting the hang of creating liquid layouts in AS2.0 a few months ago, and boy, is it quite a concept to grasp. Now I have to relearn everything I learned using AS3.0.Thankfully, once I understand the concept, all I have to do now is do it with unfamiliar syntax.

In this little tutorial, I’ll show AS2 and AS3 code showing the same end result. This is just very basic, just showing the differences between the two (which isn’t much), and to show how to get started with creating liquid layouts.

By the way, liquid layouts are layouts that change dynamically according the stage’s size. Not unlike liquid in a container, which takes the container’s size and shape, thus the name. ;-)

The movie shows 4 boxes I drew on four sides of the stage, changing position according to the stage’s size. Obviously, you could also adjust other properties of the MovieClip, like scale, alpha, rotation, etc.

First, the AS2.0 code:

Stage.scaleMode = “noScale”;
Stage.align = “TL”;

setStage();

var stageListener:Object = new Object();

Stage.addListener(stageListener);
stageListener.onResize = function() {
setStage();
};

function setStage() {
var WIDTH:Number = Stage.width;
var HEIGHT:Number = Stage.height;

box1._x = WIDTH-box1._width;
box1._y = HEIGHT/2-(box1._height/2);
box2._x = WIDTH/2 - (box2._width/2);
box2._y = 0;
box3._x = 0;
box3._y = box1._y;
box4._x = box2._x;
box4._y = HEIGHT - box4._height;
}

AS3.0:

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

setStage();

stage.addEventListener(Event.RESIZE, stageResize);

function setStage():void{
var WIDTH:Number = stage.stageWidth;
var HEIGHT:Number = stage.stageHeight;
box1.x = WIDTH - box1.width;
box1.y = HEIGHT/2 - (box1.height/2);
box2.x = WIDTH / 2 - (box2.width/2);
box2.y = 0;
box3.x = 0;
box3.y = box1.y;
box4.x = box2.x;
box4.y = HEIGHT - (box4.height);
}

function stageResize(e:Event):void{
setStage();
}

So, there isn’t really much difference between the two. AS3 is easier to understand because of its better event handling methods.

A little explanation for the 2 codes above, since they are quite similar. The first 2 lines are very important. Basically, they are telling the player to not do anything to objects on the stage when the stage is resized, because we want to control everything that happens when the stage is resized by code. Without those lines, the movie won’t work as expected.

The setStage() function is pretty self explanatory, it is where we do all the positioning of the movieclips. I like to put all of the code that does the positioning, resizing, etc. work in a function (preferably rolled into one), so I could call it at least once anytime I want. This is useful when initializing the movie, where all the movieclips might not be in their right place. And it is easier to put into the listener function too. You could also do it in the listener function, but I don’t recommend it.

We then call the setStage() function at least once, to position our movieclips where they should be, because when I created them in Flash, they are pretty much all over the place. If we don’t call that function, then they’ll only fall into place when we start resizing the stage.

And now to the part where the two codes are most different. Adding listeners to the stage. In AS3, it is quite straightforward. We add a listener, in this case stageResize() and listen to RESIZE events, to the stage object, which does nothing but call setStage(). You could also add other functions in there if you want to do something else when the stage resizes. In AS2, we have to create a listener object, tell that object to listen for the resizing event and execute the setStage() function. Again, you could add other functions in there.

So, there you have it. A basic Flash liquid layout. I hope this helps anyone who is having a hard time understanding this concept (I know I did). Now, this tutorial only showed changing the position of movieclips, by assigning values to them. But you could also change their position and/or size by percentages. Like 30% of the stage (I know this tutorial shows applying 50% of the stage), so you could adjust the visual elements of your movie to fit any size of resolution properly, at a limit of course.

NOTE: Notice the capital ‘S’ in Stage in the AS2 code and the small ’s’ in the AS3 code. Don’t mess those up!

Here are the source files of this tutorial.

AS2 source (Flash 8 )

AS3 source (Flash CS3)


Apr 20

Just got back from a 4 day vacation. Now  I have to  continue my  quest to  scour the internet for  everything  ActionScript.

I found this site while reading a few things about tweening classes (I’ll have a post about that soon. I can’t believe I haven’t used them.). ActionScriptCheatSheet.com offers exactly what the title says, AS cheatsheets in PDF format. There are about 2 which are in JPEG format, which is a shame, but they are still useful.

They have cheatsheets for the Papervision 3D engine, Apollo specific ones, and AS2 to AS3 migration ones as well. Go to the DOWNLOADS page of the blog to choose your sheet of choice.



Warning: Invalid argument supplied for foreach() in /home/ekininet/public_html/mindfock/blog/wp-content/plugins/syntax/syntax.php on line 184