Posts Tagged “as2”

I found a nice actionscript search engine:

http://www.hexosearch.com/

It looks like a beta for now, but I like the concept. Basically you can register your blog so the search engine will easily find actionscript talks. You can even choose AS2, AS3 or Flex.

Worth trying :)

By the way, if some of you want a bit more (direct) news about my work, and probably Soma, I’m trying to tweet a bit!

http://twitter.com/soundstep

Vote in HexoSearch

Comments 1 Comment »

A quick post for an AS2 class I wrote. I won't do that a lot as I'm not really using AS2 anymore.

Have you ever had a Button in another Button in as2? Or let's say, you wanted a onRollOver on a MovieClip and a onRelease on another MovieClip in this MovieClip?

Well, it happened to me several times and this is just not possible by using only onRelease and onRollOver in the same time. In AS2, the first onRelease or whatever you use that will give a pointer cursor will "block" the onRelease/onRollOver of the children, annoying...

In AS3, life is easy, you manage it with the mouseChildren and buttonMode properties.

I don't know how you solved this problem, maybe there's another simpler solution (let me know, I'm curious) but mine was to play with the hitTest method of the MovieClip.

I wrote a class that I found useful for me. After creating a instance with the MovieClip target as a parameter, the class dispatch a MouseManager.MOUSE_OVER and MouseManager.MOUSE_OUT.

You can see a demo and download the source.

The code of the class:

Actionscript:
  1. /*
  2. *
  3. * Copyright info: Free to use and change, an notification email will be welcome for a commercial use
  4. * Actionscript: built for actionscript 2.0
  5. * 05-2008
  6. *
  7. * @author      Romuald Quantin - romu@soundstep.com - www.soundstep.com
  8. * @version    1.0
  9. * @usage
  10. *
  11. */
  12.  
  13.  
  14. import mx.utils.Delegate;
  15. import mx.events.EventDispatcher;
  16.  
  17. class com.soundstep.utils.managers.MouseManager {
  18.    
  19.     private var __target:MovieClip;
  20.     private var __mouseListener:Object;
  21.     private var __over:Boolean = false;
  22.     private var dispatchEvent:Function;
  23.    
  24.     public var addEventListener:Function;
  25.     public var removeEventListener:Function;
  26.    
  27.     public static var MOUSE_OVER:String = "mouse_over";
  28.     public static var MOUSE_OUT:String = "mouse_out";
  29.    
  30.     public function MouseManager(target:MovieClip) {
  31.         EventDispatcher.initialize(this);
  32.         __target = target;
  33.         __mouseListener = {};
  34.         Mouse.addListener(__mouseListener);
  35.         __mouseListener.onMouseMove = Delegate.create(this, mouseOverOut);
  36.         mouseOverOut();
  37.     }
  38.    
  39.     // PRIVATE
  40.     //__________________________________________________________
  41.    
  42.     private function mouseOverOut():Void {
  43.         var xMousePos:Number = _level0._xmouse;
  44.         var yMousePos:Number = _level0._ymouse;
  45.         if (__target.hitTest(xMousePos, yMousePos, true)) {
  46.             if (!__over) {
  47.                 __over = true;
  48.                 this.dispatchEvent({type:MouseManager.MOUSE_OVER, target:__target});
  49.             }
  50.         }
  51.         else {
  52.             if (__over) {
  53.                 __over = false;
  54.                 this.dispatchEvent({type:MouseManager.MOUSE_OUT, target:__target});
  55.             }
  56.         }
  57.     }
  58.    
  59.     // PUBLIC
  60.     //__________________________________________________________
  61.    
  62.     public function get over():Boolean {
  63.         return __over;
  64.     }
  65.    
  66. }

and how to use it:

Actionscript:
  1. import mx.utils.Delegate;
  2. import com.soundstep.utils.managers.MouseManager;
  3.  
  4. var mm:MouseManager = new MouseManager(mc);
  5. mm.addEventListener(MouseManager.MOUSE_OVER, Delegate.create(this, mouseOver));
  6. mm.addEventListener(MouseManager.MOUSE_OUT, Delegate.create(this, mouseOut));
  7.  
  8. var t:String = mc.mcText.text;
  9.  
  10. function mouseOver():Void {
  11.     mc.mcText.text = t + " rollover";
  12. }
  13.  
  14. function mouseOut():Void {
  15.     mc.mcText.text = t;
  16. }
  17.  
  18. mc.bt.onRollOver = function():Void {
  19.     this.btText.text = "Button in MovieClip rollover";
  20. }
  21.  
  22. mc.bt.onRollOut = function():Void {
  23.     this.btText.text = "Button in MovieClip";
  24. }

Vote in HexoSearch

Comments 4 Comments »

Here is an example to show a element like a background, a image in a portfolio or whatever and make it fitting the browser.

In the demo you can choose three modes.

Mode Fit

The picture is fitting the browser regardless the original ratio. The formula is simple:

imagePositionX = 0
imagePositionY = 0
imageWidth = stageWidth
imageHeight = stageHeight

Mode Out (I called it like that because you'll miss a part of the picture)

The picture is fitting the browser as well but we keep the ratio, we'll miss a part of the picture at the right or the bottom in my example.

ratio = initialImageWidth / initialImageHeight
newWidth = stageWidth
newHeight = stageHeight
if (stageWidth / ratio < stageHeight) newWidth = stageHeight * ratio;
else newHeight = stageWidth / ratio;
imagePositionX = 0
imagePositionY = 0
imageWidth = newWidth
imageHeight = newHeight

Mode In

The image is fitting the browser, we also keep the ratio but we show the whole picture, we'll have a gap around depending of the size of the area.

ratio = initialImageWidth / initialImageHeight
newWidth = stageWidth
newHeight = stageHeight
if (stageWidth / ratio > stageHeight) newWidth = stageHeight * ratio
else newHeight = stageWidth / ratio
imageWidth = newWidth
imageHeight = newHeight
imagePositionX = (stageWidth * .5) - (imageWidth * .5)
imagePositionY = (stageHeight * .5) - (imageHeight * .5)

You can see a demo and download the source.


Vote in HexoSearch

Comments 2 Comments »