met
10-22-2009, 12:14 PM
Hi
I'm attempting to add a clickable banner to my flash, which simply rotates several images.
Can I adapt the following action script to pick up clicks?
I've read a whole buch of tuts and keep getting errors like "MouseEvent not defined" and I'm just confusing myself
my actionscript in Main is: (I found this on another site, but don't have a link at this time).
This works perfectly for fading images. i'd like to adapt it to pick up clicks.
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import fl.transitions.*;
import fl.transitions.easing.*
public class Main extends MovieClip
{
private var image_classes:Array;
private var timer:Timer;
private var holder_mc:MovieClip;
private const SPEED:int=5;
private var boo:Boolean=true;
private var id:int=0;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
image_classes=new Array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
createHolder();
displayImage();
}
private function createHolder():void
{
holder_mc=new MovieClip();
addChild(holder_mc);
}
private function displayImage():void
{
if(holder_mc.numChildren>0)
{
var bitmap:Bitmap=holder_mc.getChildAt(0) as Bitmap;
holder_mc.removeChild(bitmap);
}
var image_class:Class=Class(getDefinitionByName(image_classes[id]));
var imgData:BitmapData=new image_class(0,0);
var img:Bitmap=new Bitmap(imgData);
img.x=stage.stageWidth/2-img.width/2;
img.y=stage.stageHeight/2-img.height/2;
holder_mc.addChild(img);
TransitionManager.start(holder_mc,{type:Fade, direction:Transition.IN,
duration:1,easing:None.easeNone});
startDisplayTimer();
}
private function hideImage(evt:TimerEvent):void
{
TransitionManager.start(holder_mc,{type:Fade, direction:Transition.OUT,
duration:1,easing:None.easeNone});
startHideTimer();
}
private function startDisplayTimer():void
{
if(timer!=null)
timer.reset();
timer=new Timer(SPEED*1000,1);
timer.addEventListener(TimerEvent.TIMER,hideImage);
timer.start();
}
private function startHideTimer():void
{
if(timer!=null)
timer.reset();
timer=new Timer(1000,1);
timer.addEventListener(TimerEvent.TIMER,callDisplayImage);
timer.start();
}
private function callDisplayImage(evt:TimerEvent):void
{
id++;
if(id>image_classes.length-1)
id=0;
displayImage();
}
}
}
i found this click event code but I'm at a loss
myButton.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(e:MouseEvent):void
{
var request:URLRequest = new URLRequest("http://www.google.com");
navigateToURL(request, "_blank");
}
thanks.
I'm attempting to add a clickable banner to my flash, which simply rotates several images.
Can I adapt the following action script to pick up clicks?
I've read a whole buch of tuts and keep getting errors like "MouseEvent not defined" and I'm just confusing myself
my actionscript in Main is: (I found this on another site, but don't have a link at this time).
This works perfectly for fading images. i'd like to adapt it to pick up clicks.
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.*;
import fl.transitions.*;
import fl.transitions.easing.*
public class Main extends MovieClip
{
private var image_classes:Array;
private var timer:Timer;
private var holder_mc:MovieClip;
private const SPEED:int=5;
private var boo:Boolean=true;
private var id:int=0;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(evt:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
image_classes=new Array("img1.jpg","img2.jpg","img3.jpg","img4.jpg");
createHolder();
displayImage();
}
private function createHolder():void
{
holder_mc=new MovieClip();
addChild(holder_mc);
}
private function displayImage():void
{
if(holder_mc.numChildren>0)
{
var bitmap:Bitmap=holder_mc.getChildAt(0) as Bitmap;
holder_mc.removeChild(bitmap);
}
var image_class:Class=Class(getDefinitionByName(image_classes[id]));
var imgData:BitmapData=new image_class(0,0);
var img:Bitmap=new Bitmap(imgData);
img.x=stage.stageWidth/2-img.width/2;
img.y=stage.stageHeight/2-img.height/2;
holder_mc.addChild(img);
TransitionManager.start(holder_mc,{type:Fade, direction:Transition.IN,
duration:1,easing:None.easeNone});
startDisplayTimer();
}
private function hideImage(evt:TimerEvent):void
{
TransitionManager.start(holder_mc,{type:Fade, direction:Transition.OUT,
duration:1,easing:None.easeNone});
startHideTimer();
}
private function startDisplayTimer():void
{
if(timer!=null)
timer.reset();
timer=new Timer(SPEED*1000,1);
timer.addEventListener(TimerEvent.TIMER,hideImage);
timer.start();
}
private function startHideTimer():void
{
if(timer!=null)
timer.reset();
timer=new Timer(1000,1);
timer.addEventListener(TimerEvent.TIMER,callDisplayImage);
timer.start();
}
private function callDisplayImage(evt:TimerEvent):void
{
id++;
if(id>image_classes.length-1)
id=0;
displayImage();
}
}
}
i found this click event code but I'm at a loss
myButton.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(e:MouseEvent):void
{
var request:URLRequest = new URLRequest("http://www.google.com");
navigateToURL(request, "_blank");
}
thanks.