Cascading click events to nested buttons in Flash 8

:: June 28, 2008

I am just putting these as notes to myself and for people who are looking for solutions. I spend a lot of time figuring out the this and thought this might help someone else as well.

Please note that this may not be the best solution to the problem and there may be some other solutions which is smarter than this. This was what I was able to cook out with the time I had. If someone else got a better solution to this, post a comment and I will edit the post to include your solution as well.

The Problem: If you have nested movieclips/buttons in your Flash Movie and have to attach onRelease (or for that matter any button events) to the movieclips nested within the parent movieclip then there is no way you can attach onRelease events to the child movieclips, since the parent movieclip will blanket all the calls -  that being the top most element.

Let’s take this example:

image

In this case, if you specify a onRelease event for parent and then specify an onRelease calls to the other child movieclips, the onRelease event will work only for the parent and not for the child movieclips. This happens because the parent moviclip blankets all calls to the movieclips underneath it.

The only way out, in this case was to “move out” the child moviclips to the same level as the parent which wasn’t an option in my case.

Now for the solution:

There are two ways of working around this:

1) The easiest (and the nasty way) solution was to attach a movieclip of the same width and height of the actual movieclip and then assign onRelease event to the clone rather than the original. So, in this case your movie clip hierarchy would look like:

image

And you would write you action like:

parentMC.clone.onRelease, parentMC.Child1.clone.onRelease and so on.

Now you can target the actual moviclip by assigning a action on the lines of:

parentMC.Child1.clone.onRelease = function()

{

actualTarget = this._parent;

..

..

}

2) The other way is to use the hitTest, _xmouse, _ymouse property along with the getBounds and localToGlobal function and figure out where the _xmouse and _ymouse are based on hitTest. This is a complex route (and not so fool proof) and the steps to achieve this would be something on the lines of this:

    1. Create a movieclip and name it as pointer_mc (we need to use this movieclip as the mouse pointer).
    2. Hide the mouse and use this mc as your mouse pointer
    3. Attach a MouseListener for onMouseMove and move the pointer to where the current _xmouse and _ymouse are.
    4. Store all the valid movieclips (that are being targeted in an Array)
    5. Create a onMouseDown listener which will check for the hitTest on the target movieclips specified in the array against the pointer mc. Note that the first hit will always happen on the parent and then on the child – so you need to assign the final target to a variable which will contain the last click down.
    6. Do a getBounds on the final target you dervied on.
    7. Create a new point object with the xMin and yMin values
    8. Covert the point object to actual stage coordinates using the localToGlobal method.
    9. Check to see if your _xmouse is greater than myPoint._x and if your _xmouse is lesser than myPoint._x + finalTarget._width. This is where things gets tricky, now, your finalTarget’s width will be not just be its width but also the width of the child movieclips within it.

The actual code would look like this:

this.attachMovie("pointer_id", "pointer_mc", this.getNextHighestDepth());
Mouse.hide();
pointer_mc.swapDepths(10);

var mouseListener:Object = new Object();
mouseListener.onMouseMove = function()
{
    pointer_mc._x = _xmouse;
    pointer_mc._y = _ymouse;
    updateAfterEvent();
}

var mArray:Array = [_root.mc1, _root.mc1.mc11, _root.mc1.mc11.mc112, _root.mc1.mc12];

mouseListener.onMouseDown = function()
{
    for (var i=0; i<mArray.length; i++)
    {
        if (pointer_mc.hitTest(mArray[i]))
        {
            finalTarget = mArray[i];
        }
    }
    var bounds_obj:Object = eval(finalTarget+".mc").getBounds();
    var myPoint:Object = {x:bounds_obj['xMin'], y:bounds_obj['yMin']};
    eval(finalTarget).localToGlobal(myPoint);

    if ( _xmouse >= myPoint.x && _xmouse<= ( myPoint.x + ((eval(finalTarget))._width)) && _xmouse >= myPoint.y && _ymouse<= ( myPoint.y + ((eval(finalTarget))._height)))
    {
            trace("Correct :" + finalTarget);
    }
    else
    {
        trace("Wrong");
    }
}

Mouse.addListener(mouseListener);

 

Now, the good news is if you are using AS3 then you need not worry about all these hacks you can directly use the MouseEvent.CLICK and detect the Mouse click and keep going forward. One more reason to switch to AS3.

Exclusive Career Portal for RIA Jobs in Flash/Flex/AIR

:: June 20, 2008

There has always been a need for a career portal which focused just on the niche Adobe RIA technologies – Flash, Flex, AIR, LifeCycle, BlazeDS whatever. Every now and then people keep asking me where to look for jobs in Flash & Flex and though, certain Flash and Flex User groups on Google and Yahoo are being used by potential employers to advertise jobs to a focused set of people who are “subscribed” to these groups, the focus of these groups are not really on job posts but on technical discussions on Flash and Flex. In fact some of these groups don’t allow people to post jobs on the groups. That’s when we thought why not an exclusive job site for just RIA Jobs. And here it is…

We are happy to announce the launch of a new career portal that is exclusively focused on RIA Jobs in Flash, Flex and AIR – www.FlexJobs.in. Don’t get diverted by the .in at the end of the URL it’s just there so the URL is easy to remember - the site is build for the global RIA job market.

If you happen to be on www.FlexJobs.in do visit the Profile Management Application which is located here www.FlexJobs.in/userarea. This is a user profile creator application build on Flex which allows a candidate to create his profile on the site in few easy steps and believe me, it doesn’t take more than 2 minutes to create a complete profile including the registration.

If you have any feedbacks/comments/criticism please mail it to feedback-at-flexjobs-dot-in.

Happy job hunting !

Mozilla Prism - A blurred vision?

:: October 26, 2007

There has been quite a few posts on Prism on many blogs and some comparing it against AIR and Silverlight. Thought will give it a shot to see what this new hype is about and to me it looks more to like an application that allows you to create a shortcut to a webpage on your desktop (the only difference being that you need not open a new window for yourself but Prism does it for you when you click on the link :) ). It looks to me like an XUL application which provides you a way to run a webpage "like" a application on your desktop and I don't think it qualifies "yet" to be called as a Web Platform or even any closer to that.

I think there is nothing to seriously look into this at least at this moment or when probably it supports offline synchronization of some of the most popular apps.

Create rich interfaces with Microsoft Silverlight

:: October 17, 2007

Well, if you thought I am going to be advocate the use of Silverlight by this post then you are wrong. This post is with reference to this article which I read in ZDNet India today morning.

Tony Patton, the author of this article starts it this way - "Web developers often frown on the use of technologies like Macromedia Flash or Adobe Shockwave to spice up Web interfaces. Since these technologies are not Web standards, they may not properly work in all browsers. Even so, some developers continue to use these technologies." - I don't know where he got these statistics from and all over the article he just advocates the use of Silverlight by comparing it with Flash and Shockwave - well, there was not a single point which I could buy.

And for his impressions, he goes - "I have never been a big advocate of Flash or Shockwave when building Web interfaces. One problem with a technology like Flash is learning a whole new development environment, as well as a language with ActionScript. One positive aspect of Silverlight is its usage of existing Microsoft technologies and a tool like Visual Studio 2005 -- technologies and tools that I use every day." - I assume one has to learn MS technologies afresh when getting started new, too. Just because one uses VS everyday doesn't make it easier for a non programmer to create great rich interfaces with it nor does it make a new kid in the block (Silverlight) better than the all time Rockstars of the web (ofcourse Flash and Shockwave).

"For example, a Flash application may need to communicate with a back end Web service to get data, but Silverlight can include the code to handle server communications and data loading." - Comments??

"Silverlight requires a browser plug-in just like competing technologies, so the paradigm hasn't shifted that much." - Yes except for the few browser crashes and stupid error messages.

All in all the whole article's focus seems to be more on portraying Flash and Shockwave as negative more than speaking about the strengths of Silverlight. Is this what they call as negative marketing?

[OT] - 3D Flash Designer/Programmer with experience in Papervision or Sandy

:: September 07, 2007

One of my contact is looking for a 3D Flash Designer/Programmer with experience in Papervision or Sandy (preferably in India but not a mandate). Here is the JD, if anyone is interested mail their CV to kp [at] lastashero [.] com

3D Flash Designer/Programmer with experience in Papervision or Sandy


The project involves creating a 3D avatar which can be customized by users  i.e. size, height, color skin etc. The avatar will be able to rotate up to 180 degrees. The data for all parts of the avatar should be stored in an XML file. 

ActionScript 3.0 - Display Object Primer - Tutorial

:: June 25, 2007

After a reaaaaaaaaaaaaaaaly long time if found some free time to post a new tutorial in the tutorial section of the site. When I analyze the Google Analytics report of my site I find that even though I have not been actively posting for a while I still have a lot of people who benefit by reading my tutorials and that a good enough reason for me to continue to spend some time in writing those to the lovely users of my site :)

Here you go..   

ActionScript 3.0 - Display Object Primer - Part 1

The next parts would cover in more detail - working with DisplayObjects in ActionScript 3.0.

Apollo Alpha on Labs now !!!

:: March 19, 2007

The long awaited public alpha of Adobe Apollo is out in the labs. Go grab you copy here: http://www.adobe.com/go/apollo

You can find a lot of useful information in the Wiki.

ActionScript 3.0 Tutorial - Timer Class

:: January 03, 2007

Have posted a new tutorial on using the Timer Class in ActionScript 3.0. Check it out here.

Is Orkut hacked?

:: December 29, 2006

Social networking site Orkut has been down for almost 18hrs now and even the under maintenance page is not reachable. Usually when there is a maintenance it would be delayed for this long. I hope this is not another bad day for Google.

Merry Christmas to my readers !!!

:: December 25, 2006

Wish you all a Happy Christmas filled with joy and happiness !!!