views:

170

answers:

3

Hi there first timer here.

I'm building a flash animation using the tweenlite library. It's extremely simple which is why this is so aggravating. It's basically a slideshow with 5 frames that crossfade. When a button that calls up the next frame fades out, I'd like to disable any actions it has on it. Currently it fades out, but when you roll over it you get the button cursor, and the overstate brings the opacity back up.

I am really a noob in flash so I'm sure this is extremely simple.

thanks, Ryan

+1  A: 

Anyway, there is no direcy way of deleting objects in AS even though you have a new operator to create one. All objects are garbage collected when there are no strong references of that object. Here are two things that you can do:

  • When adding event handlers to the button object or whatever, mark them as weak OR set the eventhandlers to NULL when you are through

  • Though there is no explicit delete in AS you can set the object to null using the var = null syntax to enable the garbage collector to mark it as read y for cleanup.

dirkgently
A: 

In case you are really using AS2 (?) - as far as I remember - you should use a MovieClip instance instead of a Button. Buttons will always keep the hand cursor whilst MovieClips can swap behavior depending if any mouse handlers are attached or not.

Whenever you want to deactivate the mouse actions you should just remove the handler(s) you previously had defined (e.g. myButton.onRelease = null; myButton.onMouseOver = null; ...).

In case you are actually using AS3, you should first remove all related event listeners (e.g. myButton.removeEventListener(MouseEvent.CLICK, clickHandler);)

Then set its buttonMode to false just to avoid the hand cursor showing up although the "click functionality" has been removed (myButton.buttonMode = false;).

Hope it makes sense.

Theo.T
A: 

Most slide shows that I see are restartable, or will loop on their own. I do not believe what you want is to remove the functionality, but merely to remove the control for a specific time. Upon MOUSE_DOWN or CLICK, you can easily disable the button by using

var slidesContainer:Sprite = new Sprite();

var slideButton:Sprite = new Sprite();
slideButton.graphics.beginFill(0x000000);
slideButton.drawRect(0,0,100,30);
slideButton.endFill();
addChild(slidebutton);

slideButton.addEventListener(MouseEvent.MOUSE_DOWN, onButtonDown);

var slide01:MovieClip = new Slide();
slidesContainer.addChild(slide01);
var slide02:MovieClip = new Slide();
slidesContainer.addChild(slide02);

//Store references to the newly created movieclips in an array.
var arrayOfSlides:Array = [slide01, slide02];
var currentSlide:int = 0;

function onBtnDown(e:MouseEvent):void
{
     TweenLite.to(arrayOfSlides[currentSlide], 1, {alpha: 0});
     e.target.mouseEnabled = false;  //The button that was pressed down is the target

     currentSlide++;
}

This way we merely make the object invisible and disable it's mouse functionality.

It is a great idea to prepare objects for Garbage Collection when not needed, but it is important to know what you want to do with your work. If you wish to never use the object again, remove any references by setting to null. If you exporting to flash player 10, there is the unloadAndStop method that greatly helps in completely removing items and prepping for GC.

If you plan on reusing things, as in your slideshow restarting after a certain amount of time, etc, you would merely set the visiblity and mouseEnabled properties of the buttons back to true.

Brian Hodge blog.hodgedev.com hodgedev.com

Brian Hodge