LogoLogo
  • Home
  • Projects
  • About
  • Contact

enabled v. mouseEnabled & Other Stuff

Devon O. · August 20, 2008 · Actionscript, Flash, Life · 0 comments
2

In my last post (about the OBO_BoxTransition), Senocular had mentioned in a comment that the demo app was throwing an error when double clicking. While he never did come back to say what the error was, he’s a pretty sharp cookie, so I figured there had to be something to it. So, I finally downloaded the Flash 10 Debug player (which, incidentally, is now available), ran the .swf in it and saw immediately what the problem was. The bottom line is that the buttons, which I knew should not be clicked in rapid succession, were still firing an Event.CLICK event even after I had called a disabling method which, in short, looped through an array of SimpleButton instances (don’t know why I didn’t choose a Vector – still getting used to the idea, I suppose) and set each member’s enabled property to false. You’d think that would make the SimpleButton’s unclickable, but you’d be wrong. For a brief moment, even with a false enabled property, they are still able to be clicked and will still dispatch the corresponding event. On an impulse, however, I made the quick change from enabled to mouseEnabled and – shazam! – no more double click blues. I am not sure why using the mouseEnabled property should succeed where just plain enabled fails when dealing with SimpleButton objects, but, in the future, just to be on the safe side, I’m sticking to mouseEnabled. And just to be on the really safe side, I rewrote the init() method of the OBO_BoxTransition class using a try…catch block that guarantees the transition will not try to take place if the _currentimage is not a child of the _imgparent (which is really what the underlying error was blabbing at me). You can see the revised class file in its entirety below, if interested.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.onebyonedesign.transitions {
 
    import caurina.transitions.Tweener;
    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.EventDispatcher;
    import flash.events.ProgressEvent;
 
    /**
    * 3D "Box like" transition between to images, sprites, or movieclips.
    * Throws Event.COMPLETE when transition is finished.
    * Requires caurina.transitions package.
    * @author Devon O.
    */
    public class OBO_BoxTransition extends EventDispatcher implements ITransition {
 
        public static const UP:String = "up";
        public static const DOWN:String = "down";
        public static const LEFT:String = "left";
        public static const RIGHT:String = "right";
 
        private var _direction:String;
        private var _currentimage:DisplayObject;
        private var _newimage:DisplayObject;
        private var _time:Number;
 
        private var _imgparent:DisplayObjectContainer;
        private var _box:Sprite;
        private var _orgIndex:int;
        private var _orgY:Number;
        private var _orgX:Number;
 
        /**
         *
         * @param    image that will be transitioned out (must already be on display list).
         * @param    image that will be transitioned in
         * @param    direction in which the out image should travel.
         *             Choices are OBO_BoxTransition.LEFT, OBO_BoxTransition.RIGHT, OBO_BoxTransition.UP, or OBO_BoxTransition.DOWN
         * @param    time in seconds transition should take place.
         */
        public function OBO_BoxTransition(currentimage:DisplayObject, newimage:DisplayObject, direction:String = "left", time:Number = 1) {
            _imgparent = currentimage.parent;
            _orgX = currentimage.x;
            _orgY = currentimage.y;
            _currentimage = currentimage;
            _newimage = newimage;
            _time = time;
            _direction = direction;
        }
 
        public function start():void {
            init();
            beginTransition();
        }
 
        public function get direction():String { return _direction; }
 
        public function set direction(value:String):void {
            _direction = value;
        }
 
        public function get currentimage():DisplayObject { return _currentimage; }
 
        public function set currentimage(value:DisplayObject):void {
            _currentimage = value;
        }
 
        public function get newimage():DisplayObject { return _newimage; }
 
        public function set newimage(value:DisplayObject):void {
            _newimage = value;
        }
 
        public function get time():Number { return _time; }
 
        public function set time(value:Number):void {
            _time = value;
        }
 
        private function init():void {
            try {
                var w:int = _currentimage.width * .5;
                var h:int = _currentimage.height * .5;
                _orgIndex = _imgparent.getChildIndex(_currentimage);
                _box = new Sprite();
                _box.x = _currentimage.x;
                _box.y = _currentimage.y;
                _imgparent.addChildAt(_box, _orgIndex);
                _box.x += _currentimage.width * .5;
                _box.y += _currentimage.height * .5;
                _currentimage.y = -_currentimage.height * .5;
                _currentimage.x = -_currentimage.width * .5;
 
                switch(_direction) {
                    case "up" :
                        _box["z"] = h;
                        _currentimage["z"] -= h;
                        _newimage.x = _currentimage.x;
                        _newimage.y = _currentimage.y + (h * 2);
                        _newimage["rotationX"] = 90;
                        _newimage["z"] -= h;
                        _box.addChild(_newimage);
                        break;
                    case "down" :
                        _box["z"] = h;
                        _currentimage["z"] -= h;
                        _newimage.x = _currentimage.x;
                        _newimage.y = _currentimage.y;
                        _newimage["rotationX"] = -90;
                        _newimage["z"] += h;
                        _box.addChild(_newimage);
                        break;
                    case "left" :
                        _box["z"] = w;
                        _currentimage["z"] -= w;
                        _newimage.x = _currentimage.x + (w * 2);
                        _newimage.y = _currentimage.y;
                        _newimage["rotationY"] = -90;
                        _newimage["z"] -= w;
                        _box.addChild(_newimage);
                        break;
                    case "right" :
                        _box["z"] = w;
                        _currentimage["z"] -= w;
                        _newimage.x = _currentimage.x;
                        _newimage.y = _currentimage.y;
                        _newimage["rotationY"] = 90;
                        _newimage["z"] += w;
                        _box.addChild(_newimage);
                        break;
                }
 
                _box.addChild(_currentimage);
            } catch (e:Error) {
                // Error suppression. User has attempted to flip image in the process of transition.
            }
        }
 
        private function beginTransition():void {
            switch(_direction) {
                case "up" :
                    flipUp();
                    break;
                case "down" :
                    flipDown();
                    break;
                case "left" :
                    flipLeft();
                    break;
                case "right" :
                    flipRight();
                    break;
            }
        }
 
        private function flipLeft():void {
            Tweener.addTween(_box, { rotationY:90, time:_time, transition:"easeOutQuad", onUpdate:checkAngle, onComplete:transitionDone } );
        }
 
        private function flipRight():void {
            Tweener.addTween(_box, { rotationY:-90, time:_time, transition:"easeOutQuad", onUpdate:checkAngle, onComplete:transitionDone } );
        }
 
        private function flipUp():void {
            Tweener.addTween(_box, { rotationX:-90, time:_time, transition:"easeOutQuad", onUpdate:checkAngle, onComplete:transitionDone } );
        }
 
        private function flipDown():void {
            Tweener.addTween(_box, { rotationX:90, time:_time, transition:"easeOutQuad", onUpdate:checkAngle, onComplete:transitionDone } );
        }
 
        private function checkAngle():void {
            if (Math.abs(_box["rotationY"]) > 75 || Math.abs(_box["rotationX"]) > 75) {
                _currentimage.visible = false;
            }
        }
 
        private function transitionDone():void {
            _imgparent.removeChild(_box);
            _box = null;
            _newimage.x = _orgX;
            _newimage.y = _orgY;
            _newimage["z"] = 0;
            _newimage["rotationY"] = 0;
            _newimage["rotationX"] = 0;
            _imgparent.addChildAt(_newimage, _orgIndex);
            dispatchEvent(new Event(Event.COMPLETE));
        }
    }
}

gTween

Grant Skinner just released a new tweening by the name of gTween. Now, personally I’m getting nearly as bored (or perhaps overwhelmed is a better word) with tweening engines as I am with 3D engines, but let’s face it, when Grant Skinner talks actionscript, actionscripters listen. So, I downloaded the thing and gave it a test drive and have to say, not too shabby. I especially like the AS3 event handling syntax (rather than the callback syntax that most other engines seem to use). I also rather liked the proxy property. Very clever and very useful. Kind of missed having an update event, but it was easy enough to add one myself to the tickHandler method. GTween also comes with some easy to use sequencing and built in resource management (and from Grant Skinner, that’s saying a lot). A full list of features is included in the documentation:

  • frame or time based animation engine
  • works with any numeric properties on any object (not just display objects)
  • sequenced tweens using nextTween
  • synchronized child tweens
  • pause and resume individual tweens or all tweens
  • jump directly to the end or beginning of a tween with .end() or .beginning()
  • jump to any arbitrary point in the tween with .position
  • auto hide for alpha tweens, sets visible to false when alpha is 0 or less with .autoHide
  • smart tweening for rotation (rotates in the shortest direction) with .useSmartRotation
  • uses setSize calls when supported for width and height tweens (good for Flash and Flex components)
  • complete, activate and init events
  • configurable progress events indicate when specified points in the tween are reached
  • smart garbage collector interactions (prevents collection while active, allows collection if target is collected)
  • uses any standard ActionScript tween functions
  • support for tweening objects like colorTransform and matrix that need to be reassigned to a property
  • Overall, I really like it, but to be honest, I probably won’t be switching from Tweener, which I’ve really come to appreciate. Of course, it’s really not a matter of picking one over another, but using the right tool for the right job, and I am certain that gTween will be just what the doctor ordered sooner or later.

    Useful Library Links Galore

    If you’ve been hard up to find any useful AS3 libraries lately, I just ran across a great collection. So much code – so little time…

    SWFExplorer

    I haven’t tried this out yet, but if it’s from Thibault Imbert, it has to be good. It’s a handy utility class that will rummage through a loaded .swf file and sniff out the names of included classes and return them in Array form. Of course they can then be used with Application.getDefinition() to construct instances. Not sure how useful it would be at runtime, but maybe as an AIR application that allows you to explore .swf files given to you as resource libraries by fellow developers, etc. I know there’s times already that I could have used something of the sort.

    And Now for Something Completely Different

    Quite possibly my favorite musician David Tibet (David Michael Bunting) of Current 93 is not only a musical super genius, but student of Coptic (for those who don’t know Current 93’s probably largest influence is early Christian mythology and many of Tibet’s lyrics, writings, paintings, etc show a distinctly Gnostic flavor, many of the Gnostic texts being written in, you guessed it, Coptic). Recently, Tibet attended the 2nd International Summer School of Coptic Papyrology in Leipzig (quite a mouthful) and worked with the professor there translating a so far unpublished vellum codex of the Martyrdom of the Coptic Saint Apa Prau. You can get a gander of him in the Leipzig newspaper, Leipziger Volkszeitung here. Great stuff. I’m sure some of this experience will seep into the Hallucinatory Mountain trilogy currently in the works. The caption reads:

    What could be meant by this? In the library of the University of Leipzig, the English researcher David Tibet tries to decipher fragments of text about the Egyptian saint Apa Prau. His most important work tools are his magnifying glasses, whether on his head or in his hand. He is one of twenty academics from all over the world who are in Leipzig learning to read the contents of old papri. The week-long course was organised by the library and the Egyptian Institute.

      Facebook   Pinterest   Twitter   Google+
    • AS3 Gallery Component
      December 28, 2007 · 1 comments
      1950
      2
      Read more
    • Sleep Has His House
      February 23, 2008 · 0 comments
      2036
      3
      Read more
    • Polarizer
      November 22, 2008 · 2 comments
      2017
      4
      Read more

    Leave a Comment! Cancel reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Devon O. Wolfgang

    AIR | Unity3D | AR/VR

    Unity Certified Developer

    Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

    Reviewer of “The Starling Handbook”

    Unity Engineer at Touch Press.

    Categories
    • Actionscript (95)
    • AIR (16)
    • Flash (99)
    • Games (7)
    • Liberty (13)
    • Life (53)
    • Shaders (20)
    • Unity3D (21)
    Recent Comments
    • MainDepth on Unity Ripple or Shock Wave Effect
    • Devon O. on Unity Ripple or Shock Wave Effect
    • Feral_Pug on Unity Ripple or Shock Wave Effect
    • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
    • Danielius Vargonas on Custom Post Processing with the LWRP
    Archives
    • December 2020 (1)
    • December 2019 (1)
    • September 2019 (1)
    • February 2019 (2)
    • December 2018 (1)
    • July 2018 (1)
    • June 2018 (1)
    • May 2018 (2)
    • January 2018 (1)
    • December 2017 (2)
    • October 2017 (1)
    • September 2017 (2)
    • January 2017 (1)
    • July 2016 (1)
    • December 2015 (2)
    • March 2015 (1)
    • September 2014 (1)
    • January 2014 (1)
    • August 2013 (1)
    • July 2013 (1)
    • May 2013 (1)
    • March 2013 (2)
    • December 2012 (1)
    • November 2012 (1)
    • September 2012 (3)
    • June 2012 (2)
    • May 2012 (1)
    • April 2012 (1)
    • December 2011 (2)
    • October 2011 (3)
    • September 2011 (1)
    • August 2011 (1)
    • July 2011 (1)
    • May 2011 (2)
    • April 2011 (2)
    • March 2011 (1)
    • February 2011 (1)
    • January 2011 (2)
    • December 2010 (3)
    • October 2010 (5)
    • September 2010 (1)
    • July 2010 (2)
    • May 2010 (5)
    • April 2010 (2)
    • March 2010 (7)
    • February 2010 (5)
    • January 2010 (5)
    • December 2009 (3)
    • November 2009 (1)
    • October 2009 (5)
    • September 2009 (5)
    • August 2009 (1)
    • July 2009 (1)
    • June 2009 (2)
    • May 2009 (6)
    • April 2009 (4)
    • March 2009 (2)
    • February 2009 (4)
    • January 2009 (1)
    • December 2008 (5)
    • November 2008 (2)
    • September 2008 (1)
    • August 2008 (6)
    • July 2008 (6)
    • June 2008 (9)
    • May 2008 (4)
    • April 2008 (3)
    • March 2008 (4)
    • February 2008 (9)
    • January 2008 (7)
    • December 2007 (6)
    Copyright © 2021 Devon O. Wolfgang