addEventListener

Hi everyone,

I’m having a really annoying problem with eventListeners in my document class. No matter what I do mouse overs just don’t seem to work.

The section that’s bothering me is the link1923.addEventListener section.

Basically I want it to go from alpha 0.3 to alpha 1 when the user mouses over it but nothing happens with the way I have it coded.

Please help!!

Here’s my code

[COLOR=“RoyalBlue”]package {

// import all the necessary packages
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.*;
import flash.events.*;
import flash.events.EventDispatcher;
import flash.utils.Timer;
import fl.transitions.*;
import fl.transitions.easing.*;
import flash.media.*;
import flash.net.*;
import Test;

// begining of Main class
public class Main extends MovieClip 
{
	
	// define global variables
	public var xMid:Number = 640;
	public var yMid:Number = 512;
	public var xLeft:Number = 0;
	public var xRight:Number = 1280;
	public var yTop:Number = 0;
	public var yBottom:Number = 1024;
	public var sixtiesBack:SixtiesBack = new SixtiesBack();
	public var cigs:Cigs = new Cigs();
	public var portfolio:Portfolio = new Portfolio();
	public var artwork:Artwork = new Artwork();
	public var resumeBadge:ResumeBadge = new ResumeBadge();
	public var breadBadge:BreadBadge = new BreadBadge();
	public var newspaper:Newspaper = new Newspaper();
	public var lighting:Lighting = new Lighting();
	public var myName:MyName = new MyName();
	public var link1923:Link1923 = new Link1923();
	public var link1952:Link1952 = new Link1952();
	public var link1988:Link1988 = new Link1988();
	public var line:Line = new Line();
	public var pencil:Pencil = new Pencil();
	public var musicOff:MusicOff = new MusicOff();
	public var musicOn:MusicOn = new MusicOn();
	
	// define music variables 
	public var snd:Sound = new Sound();
	public var channel:SoundChannel;
	
	// begin contructor function
	public function Main()
	{
		
		// add an event listener to start enterSixties as soon as the frame is entered
		addEventListener(Event.ENTER_FRAME, enterSixties);
		
		// define the frame rate of the movie
		stage.frameRate = 40;
		
		// position the background
		sixtiesBack.x = xMid;
		sixtiesBack.y = yMid;
		cigs.alpha = 1;
		addChild(sixtiesBack);
		
		// position the portfolio
		portfolio.x = xLeft;
		portfolio.y = 500;
		portfolio.rotation += -2;
		portfolio.alpha = 0;
		addChild(portfolio);
		
		// position the artwork
		artwork.x = xLeft;
		artwork.y = 450;
		artwork.rotation += 2;
		artwork.alpha = 0;
		addChild(artwork);
		
		// position the pencil
		pencil.x = xRight;
		pencil.y = 330;
		pencil.alpha = 0;
		addChild(pencil);
		
		// position the resumeBadge
		resumeBadge.x = xLeft;
		resumeBadge.y = 600;
		resumeBadge.alpha = 0;
		addChild(resumeBadge);
		
		// position the breadBadge
		breadBadge.x = xMid;
		breadBadge.y = yTop;
		breadBadge.alpha = 0;
		addChild(breadBadge);
		
		// position the newspaper
		newspaper.x = 670;
		newspaper.y = yTop;
		newspaper.alpha = 0;
		addChild(newspaper);
		
		// position the myName
		myName.x = 900;
		myName.y = 797;
		myName.alpha = 0;
		addChild(myName);
		
		// position the link1923
		link1923.x = 300;
		link1923.y = 800;
		link1923.alpha = 0;
		addChild(link1923);
		
		// position the link1952
		link1952.x = 370;
		link1952.y = 800;
		link1952.alpha = 0;
		addChild(link1952);
		
		// position the link1988
		link1988.x = 440;
		link1988.y = 800;
		link1988.alpha = 0;
		addChild(link1988);
		
		// position the line
		line.x = 657;
		line.y = 820;
		line.alpha = 0;
		addChild(line);
		
		// position the cigs
		cigs.y = yBottom;
		cigs.x = xMid;
		cigs.alpha = 1;
		addChild(cigs);
		
		// position the musicOff
		musicOff.y =200;
		musicOff.x = 290;
		musicOff.rotation += -2;
		musicOff.alpha = 1;
		addChild(musicOff);
		
		// position the musicOn
		musicOn.y = 198;
		musicOn.x = 345;
		musicOn.rotation += -2;
		musicOn.alpha = 1;
		addChild(musicOn);
		
		// position the lighting
		lighting.x = xMid;
		lighting.y = yMid;
		lighting.alpha = 1;
		addChild(lighting);
		
		/*portfolio.mask = lighting;
		portfolio.cacheAsBitmap = true;
		lighting.cacheAsBitmap = true;*/
		
		// begining of the sixtiesMusic function
		function sixtiesMusic() 
		{
			snd.load(new URLRequest('fortunate son.mp3'));
			snd.addEventListener(IOErrorEvent.IO_ERROR,onIOError, false, 0, true);
			
			function onIOError(evt:IOErrorEvent):void 
			{
				trace("An Error Occurred When Loading The Sound:", evt.text);
			}
			
			snd.addEventListener(Event.COMPLETE, onLoadComplete, false, 0, true);
			function onLoadComplete(evt:Event):void
			{
				var localSnd:Sound = evt.target as Sound;
				channel = localSnd.play();
				
				var trans:SoundTransform = new SoundTransform();
				trans.volume = .2;
				channel.soundTransform = trans;

			}
		
		}
			// end of the sixtiesMusic function
			
			/*musicOff.addEventListener(MouseEvent.MOUSE_DOWN,MusicOff);
				//musicOn.addEventListener(MouseEvent.MOUSE_DOWN,MusicOn);

				function MusicOff(evt:MouseEvent):void
				{
					var pausePos:Number = channel.position;
					channel.stop();
				}*/
	
			
		 sixtiesMusic();
		
		
	// begining of the enterSixties function
	function enterSixties(evt:Event):void 
	{	
		
		if (cigs.y == yBottom) {
		var cigsMoveTween:Tween = new Tween(cigs, "y", Regular.easeOut, yBottom, 800, 2, true);
		var cigsAlphaTween:Tween = new Tween(cigs, "alpha", Regular.easeOut, 0, 1, 3, true);
		var portfolioMoveTween:Tween = new Tween(portfolio, "x", Regular.easeOut, xLeft, 450, 2, true);
		var portfolioAlphaTween:Tween = new Tween(portfolio, "alpha", Regular.easeOut, 0, 1, 3, true);		
		var artworkMoveTween:Tween = new Tween(artwork, "x", Regular.easeOut, xRight, 850, 2, true);
		var artworkAlphaTween:Tween = new Tween(artwork, "alpha", Regular.easeOut, 0, 1, 3, true);		
		var resumeBadgeMoveTween:Tween = new Tween(resumeBadge, "x", Regular.easeOut, xLeft, 350, 2, true);
		var resumeBadgeAlphaTween:Tween = new Tween(resumeBadge, "alpha", Regular.easeOut, 0, 1, 3, true);		
		var breadBadgeMoveTween:Tween = new Tween(breadBadge, "y", Regular.easeOut, yTop, 250, 2, true);
		var breadBadgeAlphaTween:Tween = new Tween(breadBadge, "alpha", Regular.easeOut, 0, 1, 3, true);		
		var newspaperMoveTween:Tween = new Tween(newspaper, "y", Regular.easeOut, yBottom, 915, 2, true);
		var newspaperAlphaTween:Tween = new Tween(newspaper, "alpha", Regular.easeOut, 0, 1, 3, true);		
		var myNameAlphaTween:Tween = new Tween(myName, "alpha", Regular.easeOut, 0, 0.5, 3, true);		
		var link1923AlphaTween:Tween = new Tween(link1923, "alpha", Regular.easeOut, 0, 0.3, 3, true);		
		var link1952AlphaTween:Tween = new Tween(link1952, "alpha", Regular.easeOut, 0, 0.3, 3, true);		
		var link1988AlphaTween:Tween = new Tween(link1988, "alpha", Regular.easeOut, 0, 0.3, 3, true);		
		var lineAlphaTween:Tween = new Tween(line, "alpha", Regular.easeOut, 0, 0.3, 3, true);		
		var pencilMoveTween:Tween = new Tween(pencil, "x", Regular.easeOut, xRight, 950, 2, true);		
		var pencilAlphaTween:Tween = new Tween(pencil, "alpha", Regular.easeOut, 0, 1, 3, true);		
		}
		
		link1923.addEventListener(MouseEvent.MOUSE_OVER, link1923Over);

		function link1923Over(evt:MouseEvent):void
			{
				if (link1923.alpha == 0.3)
				{
					link1923.alpha = 1;
				}
			}
		
		}
		
	}

}

}[/COLOR]

If you’d rather download the .fla please go to http://www.joegardner.co.uk/flash/main.as

or to see the thing ‘in action’ http://www.joegardner.co.uk/flash/main.html

Thanks