Thursday, July 23, 2009

Cool Flash Tip of the Week 5

Hey Flashers, I know its been a long time since the last tip. Time has not been on my side recently, but I'm getting some more free time and I'll be posting regularly again. Be on the look out, I have some new websites and articles coming out. You can see the latest website to date, Galley Smith Blog. But aside from all of that, down to the tip.



I'm currently working on a 3D Flash site and I decided to use Flash 10 3D instead of Papervision3D. I felt it would be overkill to use Papervision for this project since we couldn't get our animated 3d models into Papervision successfully. As everyone knows or some who don't, FP10 's z sorting is non-existent. I needed to have floating panels zoom up to show maximized version of the panel. The problem is that, scaling them up, if it is not at the top of the DisplayList, it would show the other panels in front of it still.



I needed to make a function that would always keep my selected panel above the rest. The kreativeSort function was born. Its still in its infancy, but I see potential in it. I will work on it more throughout the project at keep everyone up to date with the progress. Here is the commented function for everyone to use if you happen to have the same issue.




Update



I've been steered in a better direction and found of an alternative and faster way of doing this over at Actionscript.org from lordofduct. Check out the updated function at the bottom.






Without KreativeSort



 



With KreativeSort






/**
* Puts selected DisplayObject on top of other DisplayObects in its container
*
* @param parent Container DisplayObject that holds our children.
* @param panel Child we want to be displayed on top of the rest
*
* @author Clemente Gomez - kreativeKING
*/
private function kreativeSort(parent:DisplayObjectContainer, panel:DisplayObject) : void
{
var i : int = 0;
var length : Number = parent.numChildren;

//Position the child is located at.
var pos:int;

for (i ; i < length ; i++)
{
// When child matches the level we are at in the container, recored the level in variable "pos".
if(parent.getChildAt(i) == panel)
{
pos = i;
break;
}
}
// Removes child out of container.
parent.removeChildAt(pos);

//Adds the child back on top of the rest.
parent.addChildAt(panel, parent.numChildren);

}







Updated Function

function kreativeSort( parent:DisplayObjectContainer, panel:DisplayObject ):void
{
if (parent.contains( panel )) parent.addChild( panel );
}

5 comments:

  1. Thank you very much

    I spent a lot of time to watch your lessons ,so I hope that you provide more lessons about uses of flash & action script 3 ....
    in the end I want to say:
    good luck and keep up the good work :)

    ReplyDelete
  2. hello again

    what uses of the function addChildAt()?!!!

    ReplyDelete
  3. please delete my last comment

    thank you !

    ReplyDelete
  4. Thanks I will start this series back up in a couple weeks. Just been extremely busy lately.

    Thanks again for the support

    ReplyDelete
  5. It allows you to add a Child at a certain index

    ReplyDelete