Posted in Actionscript 3.0, Code Snippets, Other on October 30th, 2007 by Omar Faleh – Be the first to comment
Static classes are life savers for those who want a central data hubs where all shared variables are stored and accessed and modified. Some programmers think that this is dangerous since there is no real control over who gets to do what with the variables.. but for a scenario where several objects need to access the same data.. I can’t think of better ways of doing so.
here’s an example of a static class:
package com.packageName{
public class DataStore{
static var _DS:DataStore;
static var dataArray:Array;
public function DataStore(){
// write something here
}
public static function getInstance(): DataStore {
if (_DS == null) _DS = new DataStore();
return _DS;
}
public function doSomething(){
// write code here
}
}
}
and then to call the function doSomething from this class, this is the way it’s called:
com.packageName.DataStore.getInstance().doSomething();
Posted in Actionscript 3.0, Code Snippets on October 30th, 2007 by Omar Faleh – 2 Comments
I always try to opt from using the flv player component.. although it saves us half the work when it comes to accessing the properties and methods, sometimes it is still very heavy (in size) compared to this approach that really doesn’t add anything worth mentioning
import flash.media.SoundTransform;import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class videoPlayer
{
public function videoPlayer():void
{
var customClient = new Object();
customClient.onMetaData = metaDataHandler;
var nc = new NetConnection();
nc.connect(null);
var ns = new NetStream(nc);
ns.client = customClient;
var vid = new Video(320, 240);
vid.name = "vid";
this.addChild(vid);
vid.attachNetStream(ns);
ns.play("videos/videoSample.flv");
st = new SoundTransform();
st.volume=0.5;
ns.soundTransform=st;
}
public function metaDataHandler(infoObject:Object):void {
for (var prop in infoObject){
trace(prop+" : "+infoObject[prop]);
}
}
}
Posted in Adobe Technologies, Flash Technologies on October 15th, 2007 by Omar Faleh – Be the first to comment
http://www.gugga.com/GuggaFlashFramework/
I am still waiting for the Fuse library to be ported into AS3.. IU can’t bring myself to get back into the flash built-in Tween classes.
I heard some recommendations for tween-lite… I wonder if I should start dipping my feet into that puddle or just wait until I see something else emerging.
Posted in Actionscript 2.0, Code Snippets on September 19th, 2007 by Omar Faleh – Be the first to comment
let’s imagine this scenario:
we instantiate a certain number of instances of object A on the stage (_root) .. and we want each object to be receive a different value, and have that object do something with it
a real life example would be: create a client object and pass the client name as an argument to that object.
and let’s assume that we have a complex class hierarchy that requires code optimization, which generally means that we need to know how to find the code without scrolling through a 5 page long classes.
for that, we can create an Event Manager class that listens to events from all objects in the structure and handles the calls and manages the data.
a simple example would be:
read more »
Posted in Actionscript 3.0, Code Snippets on September 19th, 2007 by Omar Faleh – Be the first to comment
I am not sure that this is the best or only way of doing it.. but here’s what I found so far
what used to be _root.mcName in AS2 is gone… and now the while concept of root is also gone
according to Adobe (from the Flash CS3 help file)
the root property is the top-most display object in the portion of the display list’s tree structure represented by that SWF file
however, if you have an object on the stage with name chalk for example you can’t access it by saying: root.chalk
because root is the parent displayObject of a stage, where objects are added.
so, on the document class or on the frames, if you write:
read more »
Posted in Actionscript 3.0, Code Snippets on September 19th, 2007 by Omar Faleh – Be the first to comment
One of the biggest changes to Actiosncript 3.0 for me (which took me forever to figure out) is the method to add an object from the library by its identifier, in case that identifier was ordered.
take this screenshot for example:

to add an instance of the switchButtons movieClip to the stage all you have to write is:
var sb = new switchButtons();
stage.addChild(sb);
read more »
Posted in Actionscript 2.0, Code Snippets on September 19th, 2007 by Omar Faleh – 1 Comment
to use the Fuse classes in a custom Actionscript class, here’s how it works:
import com.mosesSupposes.fuse.*;
class customClass{
// constructor
function customClass(){
// this has to be called in the
// constructor function or the
// onLoad function to register the classes
ZigoEngine.register( Fuse, PennerEasing );
var AnimVarFuse = new Fuse();
AnimVar.push(
{
target:this.child_mc,
alpha:100 ,
seconds:0.5,
delay:0.5
},
{
scope:this,
func:functionName
}
);
AnimVar.start();
}
function functionName(){
// this is a function that will be called
// once the animation is over
// the scope refers to where
// the function is declared.. the scope
// can be _root if the function is on
// the highest level
}
}
read more »