flash - Using custom graphical assets in pure AS3 project -


I have created some button states in Flash (SCC), and I want to use them in pure AS3 project. They are movie clips with the class of neatButton_on and neatButton_off respectively, I call them like this:

  public class neatButton neatModule {private var stateOn: neatButton_on; Private Enmity State Off: Newbutton_off; Private var modContainer: Sprite = New Sprite (); Public Function Button () {addChild (modContainer); ModContainer.x = 200; ModContainer.y = 200; Stateof = new newbutton_off (); Stateon = new button_on (); ModContainer.addChild (stateOn); ModContainer.addChild (stateOff); ModContainer.addEventListener (MouseEvent.MOUSE_OVER, Hover); ModContainer.addEventListener (MouseEvent.MOUSE_OUT, Revoked); } Private function hover (e: MouseEvent): zero {stateOff.visible = false; } Private function unhur (e: MouseEvent): zero {stateOff.visible = true; }}   

My question is, is this the best way to do this? I've used assets specifically for different states of the same item, where I put everything in a movie clip and then changed the frame when needed. Is one way faster than the other? Is there any best practice?

I have two state image buttons. I use Twilight to affect alpha tiny on rollover.

  package com.b99.display.composite {import flash.display. *; Import flash.events.MouseEvent; Import com.greensock *; / ** * ... * Author @ bosworth 99 * / public class extends the Emgbutton Sprite {Personal Works _canvas: Sprite = New Sprite (); Private var _up: Sprite; Private WiiOver: Sprite; Private var _hit: size; Private Violence _intent: String; Public Function ImgButton (Intent: String) {_intent = intent; Super(); in this(); } Private work init (): zero {constructButton (); AddEventHandlers (); } Personal Function Construction Button (): Zero {this.addChild (_canvas); Switch (_intent) {case "button1": {_up = new yourUpClip1 () _over = newOverClip1 (); break; } Case "button 2": {_up = new yourUpClip2 () _over = newOverClip2 (); break; } Case "button 3": {_up = new yourUpclip3 () _over = new yourOverClip3 (); break; }} _canvas.addChild (_up); With (_over) {alpha = 0; } _canvas.addChild (_over); _hit = new size (); With {_hit} {graphics.beginFill (0x00FF40, 0); Graphics.drawRect (0, 0, _up.width + 5, _up.height +5); Graphics.endFill (); X = -5; Y = -5; } _canvas.addChild (_hit) _up.cacheAsBitmap = true; _over.cacheAsBitmap = True; _hit.cacheAsBitmap = true; This.buttonMode = true; This.mouseEnabled = true; } Private function addEventHandlers (): zero {_hit.addEventListener (MouseEvent.MOUSE_OVER, over, false, 0, true); _hit.addEventListener (MouseEvent.MOUSE_OUT, out, wrong, 0, true); } Private Function Over (e: MouseEvent): Zero {TweenLite.to (_over, .2, {Alpha: 1}); } Private Function Out (E: MouseEvent): Zero {TVLlight. To (_over, .2, {alpha: 0}); } Public function deleted (): zero {_hit.removeEventListener (MouseEvent.MOUSE_OVER, over); _hit.removeEventListener (MouseEvent.MOUSE_OUT, outside); _canvas.removeChild (_up); _up = null; _canvas.removeChild (_over); _Over = null; _canvas.removeChild (_hit); _hit = null; This.removeChild (_canvas) _canvas = null; This.parent.removeChild (this); } // +++++++++++++++++++++++++++ End +++++++++++++++ + +++++++++++++++++++++}}   

All you need to do is send it to the string that feeds in it Switch statement This kind of use can be used for multiples of this class, and then to call, just call _imgButton.destroy () in parent.

This class is similar to the same functionality for you;)

Cheers

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -