Please can anyone help me.
I’m fairly new to Actionscript 3 and I thought I was doing ok until today. I have been trying to do rollovers from the document class and nothing seems to work except eventListeners for the stage e.g. stage.addEventListener etc etc.
I added the cigs eventListener (way down at the bottom of this code) as a test to see if, when I rolled over the cig movieclip it would respond (in this case vanishing) however nothing happens. However if I change the cigs.addEventListener to stage.addEventListener then I can get results.
Please help, I need to understand why event listeners in my document class are only listening to the stage.
Thanks in advance and if you’d like to see the beginnings of my portfolio then please visit…
http://www.joegardner.co.uk/flash/main.html
the code is below…
Thanks,
Joe.
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.*;
// 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()
{
stop(); // stop the playhead moving
// 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 = 200;
musicOff.alpha = 1;
addChild(musicOff);
// position the musicOn
musicOn.y = 200;
musicOn.x = 270;
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);
}
cigs.addEventListener(MouseEvent.MOUSE_DOWN, cigsOver, false, 0, true);
if (cigs.alpha == 1)
{
function cigsOver(evt:MouseEvent)
{
cigs.alpha = 0;
}
}
}
}
}
}