/ Published in: ActionScript
Taken from a lynda.com tutorial on learning actionscript. Lots of comments for the moment.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Create a global variable to hold the current top depth available var nTopDepth:Number; //Create an associative array to store the names of the opened windows var oOpenedWindows:Object = new Object(); //Add the 2 event handles to the buttons. Passes the id name through to the addWindow function. mcButtonOne.onRelease = function():Void { addWindow("WindowOne"); }; mcButtonTwo.onRelease = function():Void { addWindow("WindowTwo"); }; function addWindow(sLinkage:String):Void { //If a value already exists in the associative array for the window, return. if(oOpenedWindows[sLinkage] != undefined) { oOpenedWindows[sLinkage].swapDepths(nTopDepth);//if the window exists, bring the existing window to the top depth return; } var nIndex:Number = this.getNextHighestDepth();//get the next highest level to put the window on var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" + nIndex, nIndex);//attach the selected window and apply the next highest depth mcWindow._x = 100;//set selected window to 100px mcWindow._y = 100;//set selected window to 100px nTopDepth = nIndex;//set the nTopDepth to nIndex we aquired above. oOpenedWindows[sLinkage] = mcWindow;//Insert a value into the associative array mcWindow.mcWindowBackground.onPress = function():Void { this._parent.swapDepths(nTopDepth);//swap the selected window with the current top depth to bring it to the front this._parent.startDrag();//target the window background, then its parent to add a drag function onPress }; mcWindow.mcWindowBackground.onRelease = function():Void { this._parent.stopDrag();//target the window background, then its parent to remove a drag function onRelease }; mcWindow.mcWindowBackground.onReleaseOutside = mcWindow.mcWindowBackground.onRelease; mcWindow.mcCloseSquare.onRelease = function():Void { delete oOpenedWindows[sLinkage]//remove the window from the array on close this._parent.removeMovieClip();//remove the movie clip when you press the close button. }; }