ActionScript 3.0 Memory Management

Posted by Matthew Hancock at 10:10 am
Tutorials No Comments »

Memory management code directly from the man at gskinner.com.
import flash.system.System;
import flash.net.navigateToURL;
import flash.net.URLRequest;
...
// check our memory every 1 second:
var checkMemoryIntervalID:uint = setInterval(checkMemoryUsage,1000);
...
var showWarning:Boolean = true;
var warningMemory:uint = 1000*1000*500;
var abortMemory:uint = 1000*1000*625;
...
function checkMemoryUsage() {
if (System.totalMemory > warningMemory && showWarning) {
// show an error to the user warning them that we're running out of memory and might quit
// try to free up memory if possible
showWarning = false; // so we don't show an error every second
} else if (System.totalMemory > abortMemory) {
// save current user data to an LSO for recovery later?
abort();
}
}
function abort() {
// send the user to a page explaining what happpened:
navigateToURL(new URLRequest("memoryError.html"));
}

You can find other system management tips at gskinner.com

AS3 Dynamic Alpha Gradient Mask

Posted by Matthew Hancock at 2:18 pm
Tutorials 1 Comment »

In the process of creating an image gallery in AS3, I ran across this interesting error.

1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.

Incorrect Code:

public class ImageGallery extends Component {
private var ldrData:URLLoader;
private var count:uint;
var holder:MovieClip;
var myMask:MovieClip;
public function ImageGallery() {
count = 0;
myMask = new MovieClip();
holder = new MovieClip();
addChild(holder);
holder.x = 50;
holder.y = 0;
myMask = addChild(new mask_mc());
holder.cacheAsBitmap = true;
myMask.cacheAsBitmap = true;
holder.mask = myMask;
if (this.stage != null) {
//Master.SetParameter("ModelId","100")
this.Initialize();
}
}
...
}

The fix for this error was simple. When declaring myMask = addChild(new mask_mc()), you can cast your variable using “as MovieClip” to fix the problem.

Corrected Code:

public class ImageGallery extends Component {
private var ldrData:URLLoader;
private var count:uint;
var holder:MovieClip;
var myMask:MovieClip;
public function ImageGallery() {
count = 0;
myMask = new MovieClip();
holder = new MovieClip();
addChild(holder);
holder.x = 50;
holder.y = 0;
myMask = addChild(new mask_mc()) as MovieClip;
holder.cacheAsBitmap = true;
myMask.cacheAsBitmap = true;
holder.mask = myMask;
if (this.stage != null) {
//Master.SetParameter("ModelId","100")
this.Initialize();
}
...
}

Missing Flash CS3 Components?

Posted by Matthew Hancock at 10:18 am
Resources No Comments »

We know there are some vital Flash components missing from Flash CS3, but there are some good third party v3 components out there that help make up for Adobe’s lack of intuition.

Jumpeye Flash Flash CS3 Components

If Architects Had To Work Like Web Designers

Posted by Matthew Hancock at 12:36 pm
Opinion 6 Comments »

Not sure who wrote this, but I DO NOT take credit for its greatness… enjoy!

————————————————————————-

Dear Mr. Architect:

Please design and build me a house. I am not quite sure of what I need, so you should use your discretion. My house should have somewhere between two and forty-five bedrooms. Just make sure the plans are such that the bedrooms can be easily added or deleted. When you bring the blueprints to me, I will make the final decision of what I want. Also, bring me the cost breakdown for each configuration so that I can arbitrarily pick one.

Keep in mind that the house I ultimately choose must cost less than the one I am currently living in. Make sure, however, that you correct all the deficiencies that exist in my current house (the floor of my kitchen vibrates when I walk across it, and the walls don’t have nearly enough insulation in them).

As you design, also keep in mind that I want to keep yearly maintenance costs as low as possible. This should mean the incorporation of extra-cost features like aluminum, vinyl, or composite siding. (If you choose not to specify aluminum, be prepared to explain your decision in detail.)

Please take care that modern design practices and the latest materials are used in construction of the house, as I want it to be a showplace for the most up-to-date ideas and methods. Be alerted, however, that kitchen should be designed to accommodate, among other things, my 1952 Gibson refrigerator.

To insure that you are building the correct house for our entire family, make certain that you contact each of our children, and also our in-laws. My mother-in-law will have very strong feelings about how the house should be designed, since she visits us at least once a year. Make sure that you weigh all of these options carefully and come to the right decision. I, however, retain the right to overrule any choices that you make.

Please don’t bother me with small details right now. Your job is to develop the overall plans for the house: get the big picture. At this time, for example, it is not appropriate to be choosing the color of the carpet.

However, keep in mind that my wife likes blue.

Also, do not worry at this time about acquiring the resources to build the house itself. Your first priority is to develop detailed plans and specifications. Once I approve these plans, however, I would expect the house to be under roof within 48 hours.

While you are designing this house specifically for me, keep in mind that sooner or later I will have to sell it to someone else. It therefore should have appeal to a wide variety of potential buyers. Please make sure before you finalize the plans that there is a consensus of the population in my area that they like the features this house has. I advise you to run up and look at my neighbor’s house he constructed last year. We like it a great deal. It has many features that we would also like in our new home, particularly the 75-foot swimming pool. With careful engineering, I believe that you can design this into our new house without impacting the final cost.

Please prepare a complete set of blueprints. It is not necessary at this time to do the real design, since they will be used only for construction bids. Be advised, however, that you will be held accountable for any increase of construction costs as a result of later design changes.

You must be thrilled to be working on as an interesting project as this! To be able to use the latest techniques and materials and to be given such freedom in your designs is something that can’t happen very often. Contact me as soon as possible with your complete ideas and plans.

PS: My wife has just told me that she disagrees with many of the instructions I’ve given you in this letter. As architect, it is your responsibility to resolve these differences. I have tried in the past and have been unable to accomplish this. If you can’t handle this responsibility, I will have to find another architect.

PPS: Perhaps what I need is not a house at all, but a travel trailer. Please advise me as soon as possible if this is the case..

ActionScript 3.0 onEnterFrame

Posted by Matthew Hancock at 4:47 pm
Tutorials, Resources 8 Comments »

In ActionScript 3.0, the frame event model has been changed from the ActionScript 2.0 version quite a bit. In ActionScript 2.0, if you wanted to perform a task every time you entered a frame, you would type

onEnterFrame = function(){
trace("Do Something");
}

In ActionScript 3.0, you must use an event listener format to perform a frame event. For example…

addEventListener(Event.ENTER_FRAME,myFunction);
function myFunction(event:Event) {
trace("Do Something");
}

It’s a little more complicated than the old way, but ActionScript 3.0 opens up a whole new world of programming possibilities.

  • Noob Flash Feeds

  • Site Tools

  • WP Theme & Icons by N.Design Studio
    Entries RSS Comments RSS Login