Subquery in MySQL 4

Posted by Matthew Hancock at 11:03 am
Tutorials No Comments »

Unfortunately, MySQL does not support a subquery until MySQL 5.0. So if you tried to use the following code:

SELECT username FROM users WHERE user_id IN (SELECT user_id FROM admins);

you would get errors. Fortunately, I have figured out a nice little work around for this problem. Using php, you can use the following code to perform a subquery type request in MySQL 4.0.

$sql = "SELECT user_id FROM admins";
$rs = mysql_query($sql);
$adminuserids = array();
while ($ra = mysql_fetch_array($rs)){
$adminuserids[] = $ra[’user_id’];
}

# Implode your array into a comma seperated string
$adminuserids = implode(’,',$adminuserids);

# Our sql with “sub query”
$sql = “SELECT username FROM users WHERE user_id IN ($adminuserids)”;

That should take care of your MySQL 4.0 subquery needs.

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();
}
...
}

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.

Tips For Migrating Your Flash Applications to ActionScript 3.0

Posted by Matthew Hancock at 11:02 pm
Tutorials, Resources No Comments »

Adobe Flash CS3 Professional includes many great new features, including the ActionScript 3.0 programming language and the ActionScript 3.0 FLA file format. This article is a summary of notes and reflections as the author migrated to using ActionScript 3.0. The article also provides solutions that address these topics:

* Changes to handling movie clips
* Changes to loading data, content, and symbols
* Changes to building object classes in ActionScript 3.0

View The Article [adobe.com]

  • Noob Flash Feeds

  • Site Tools

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