malx
01-02-2008, 03:01 PM
So in As3 I wrote this function called Fade and what it did was it would fade any MC I chose when I called it. Here's the AS2 code.
In as2...
function fadeMC($type, $mc, $op1, $op2, $speed) {
if ($type == 'in') {
$mc.alpha = $op1;
$mc.onEnterFrame = function() {
$mc.alpha = $mc.alpha+$speed;
if ($mc.alpha>=$op2) {
delete $mc.onEnterFrame;
}
};
}
if ($type == 'out') {
$mc.alpha = $op1;
$mc.onEnterFrame = function() {
$mc.alpha = $mc.alpha-$speed;
if ($mc.alpha<=$op2) {
delete $mc.onEnterFrame;
}
};
}
}
This worked great when I called somthing like..
fadeMC(myMovieClip, 'in', 0, 100, 1);
so if I had my movie set at 60fps it would take a total of 1 second to fade the alpha of the movie clip.
How would I do this in as3? I've tried creating custom event listeners but I can't seem to get it right. Is it me or is this really hard? Or is it really easy and I'm just stupid.
So far I have something like this in AS3..
package com.amediacreative.amedia {
import flash.events.*;
import flash.display.*;
class CustomEvent extends MovieClip { //not sure if I should extend MC
private var $mc:Namespace;
private var $op1:Number; // Opacity
private var $op2:Number;
private var $type:Namespace;
//this.addEventListener(Event.ENTER_FRAME,EnterFrame Handler);
public function customEvent() {
// Blank Constructor
}
public function fadeMC($type, $mc, $op1, $op2, $speed):void {
// NEED to put AS3 code here.
}
}
}
Thanks for helping me in advance!
In as2...
function fadeMC($type, $mc, $op1, $op2, $speed) {
if ($type == 'in') {
$mc.alpha = $op1;
$mc.onEnterFrame = function() {
$mc.alpha = $mc.alpha+$speed;
if ($mc.alpha>=$op2) {
delete $mc.onEnterFrame;
}
};
}
if ($type == 'out') {
$mc.alpha = $op1;
$mc.onEnterFrame = function() {
$mc.alpha = $mc.alpha-$speed;
if ($mc.alpha<=$op2) {
delete $mc.onEnterFrame;
}
};
}
}
This worked great when I called somthing like..
fadeMC(myMovieClip, 'in', 0, 100, 1);
so if I had my movie set at 60fps it would take a total of 1 second to fade the alpha of the movie clip.
How would I do this in as3? I've tried creating custom event listeners but I can't seem to get it right. Is it me or is this really hard? Or is it really easy and I'm just stupid.
So far I have something like this in AS3..
package com.amediacreative.amedia {
import flash.events.*;
import flash.display.*;
class CustomEvent extends MovieClip { //not sure if I should extend MC
private var $mc:Namespace;
private var $op1:Number; // Opacity
private var $op2:Number;
private var $type:Namespace;
//this.addEventListener(Event.ENTER_FRAME,EnterFrame Handler);
public function customEvent() {
// Blank Constructor
}
public function fadeMC($type, $mc, $op1, $op2, $speed):void {
// NEED to put AS3 code here.
}
}
}
Thanks for helping me in advance!