Showing posts with label actionscript. Show all posts
Showing posts with label actionscript. Show all posts

Jul 31, 2009

ActionScript: fade in/out

function fadeAnimation(target,show,speed) {
 target.showing = show;
 target.speed = speed;
 if(show) target._visible = true;
 
 target.onEnterFrame = function() {
  this._alpha += (this.showing) ? +this.speed : -this.speed;  
  if(this._alpha<=0 && !this.showing) {
   this._visible = false;
   delete this.onEnterFrame;
  }
  if(this._alpha>=100 && this.showing) {
   delete this.onEnterFrame;
  }
 }
}

Jul 8, 2009

Quick Tip: ActionScript: Instance Name

Here's a quick tip: Getting an instance name of a movie clip is not mc.instanceName, but mc._name. Odd, but it works.

May 5, 2009

ActionScript: Printing

function print_mc(mc) {
 
 var myPrintJob:PrintJob = new PrintJob();

 myPrintJob.start();
 myPrintJob.addPage(mc);
 myPrintJob.send();

}

Oct 30, 2008

ActionScript: Passing parameters to onRelease and other event functions

As it turns out, you can't use parameters directly when defining an event function, for example:
myMovie.onRelease = function(param1,param2,param3) {
   //my code
}
The example above will generate a compiler error. This won't work either:
var = 1;
var2 = "something else";
myMovie.onRelease = function() {
   //var and var1 are unaccessible at this point
}
The solution for this is simple, yet effective. You need to define your paramaters to a movieclip, so that you can reach them with the operator "this".
myMovie.param1 = "something";
mymovie.param2 = "something else";
myMovie.onRelease = function() {
   trace(this.param1);
   trace(this.param2);
}

Sep 24, 2008

ActionScript: Controling volume of all sounds

By creating a sound object with no target on the highest level, you can control volume of all sounds on the stage.
var s:Sound = new Sound();
s.setVolume(0);
This will mute all sounds. The setVolume() parameter is given as percentage, so the value is between 0 and 100 where 0 is muted.