PDA

View Full Version : PNG transparency blocking lower MCs?


psycholodj
04-15-2008, 09:30 PM
So basically - Each lever is a PNG animation cycle that consists of full bleed frames that are the lever + transparency. All 10 levers have the same base class attached, and they all have the same timeline structure (hit area with mouse click handler on first frame only).

Why does the top most lever block the rest? If I move another lever above it, that lever will be the only one to respond to the mouse. I was under the impression that using a hit area MC would solve the stacking and transparency woes and allow for layered levers.

BTW ignore the pause before the panel slides out - The background image gets loaded the first time you trigger the panel.

Here's the code:

package com.morrison.project {
//import classes
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;
//
//Other Main Timeline imports go here! Don't forget!
public class ProjectLever extends MovieClip {
//---------------------------------VARS
//numeric identifier
public var nID:Number = 0;
//is lever playing anim
private var bPlaying:Boolean = false;
//is lever on
public var bEnabled:Boolean = false;
//timer for hit area handler
private var tTimer:Timer;
//
public function ProjectLever() {
//enable as button
this.leverHit_mc.buttonMode = true;
//hit area for up state
this.leverHit_mc.addEventListener(MouseEvent.CLICK , mouseClickHandler);
//timer for hit area handler
this.tTimer = new Timer(100, 1);
this.tTimer.addEventListener('timer', timerHandler);
}
//set identity of lever
public function setID(n:Number):void {
this.nID = n;
trace('lever setID - '+this.nID);
}
//
//get identity of lever
public function getID():Number {
return this.nID;
trace('lever getID - '+this.nID);
}
//return lever to up state
public function goToUp():void {
this.gotoAndPlay('pullUp');
//start checking to see if back up
this.addEventListener(Event.ENTER_FRAME, this.checkIfUp);
}
//
//method to check if lever is down
private function checkIfDown(e:Event):void {
trace('current label = '+this.currentLabel);
if (this.currentLabel == 'down') {
trace('lever is down');
//remove check
this.removeEventListener(Event.ENTER_FRAME, this.checkIfDown);
//dispatch event to tell parent to load panel
(parent as MovieClip).leverDown(this.nID);
}
}
//
//method to check if lever is up
private function checkIfUp(e:Event):void {
trace('current label = '+this.currentLabel);
if (this.currentLabel == 'up') {
trace('lever is up');
//remove check
this.removeEventListener(Event.ENTER_FRAME, this.checkIfUp);
//add mouse handler back to hit area using timer delay
//this.leverHit_mc.addEventListener(MouseEvent.MOUSE _DOWN, mouseDownHandler);
tTimer.start();
}
}
//
//mouse click handler
private function mouseClickHandler(e:MouseEvent):void {
//only allow if enabled
if (this.bEnabled) {
trace('press - '+this.name);
//if not currently playing animation
if (this.currentLabel == 'up') {
this.gotoAndPlay('pullDown');
//check to see if on down state yet
this.addEventListener(Event.ENTER_FRAME, this.checkIfDown);
}
}
}
//listen for timer to fire
private function timerHandler(e:TimerEvent):void {
//add mouse down handler back to hit area
trace('timer');
//hit area for up state
this.leverHit_mc.addEventListener(MouseEvent.CLICK , mouseClickHandler);
//enable as button
this.leverHit_mc.buttonMode = true;
}
}
}

psycholodj
04-15-2008, 11:43 PM
I should add - Is it just a matter of disabling the MC itself as a button? And only enabling the hit area as a button?

psycholodj
04-15-2008, 11:47 PM
Argh - That's all it was!

this.mouseEnabled = false;

Put this in the Base Class constructor and then set it = enabled on the hit area within that MC.