Flash Window ActionScript Functionality


/ Published in: ActionScript
Save to your folder(s)

Taken from a lynda.com tutorial on learning actionscript. Lots of comments for the moment.


Copy this code and paste it in your HTML
  1. //Create a global variable to hold the current top depth available
  2. var nTopDepth:Number;
  3. //Create an associative array to store the names of the opened windows
  4. var oOpenedWindows:Object = new Object();
  5.  
  6. //Add the 2 event handles to the buttons. Passes the id name through to the addWindow function.
  7. mcButtonOne.onRelease = function():Void {
  8. addWindow("WindowOne");
  9. };
  10. mcButtonTwo.onRelease = function():Void {
  11. addWindow("WindowTwo");
  12. };
  13.  
  14. function addWindow(sLinkage:String):Void {
  15. //If a value already exists in the associative array for the window, return.
  16. if(oOpenedWindows[sLinkage] != undefined) {
  17. oOpenedWindows[sLinkage].swapDepths(nTopDepth);//if the window exists, bring the existing window to the top depth
  18. return;
  19. }
  20. var nIndex:Number = this.getNextHighestDepth();//get the next highest level to put the window on
  21. var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" + nIndex, nIndex);//attach the selected window and apply the next highest depth
  22. mcWindow._x = 100;//set selected window to 100px
  23. mcWindow._y = 100;//set selected window to 100px
  24. nTopDepth = nIndex;//set the nTopDepth to nIndex we aquired above.
  25. oOpenedWindows[sLinkage] = mcWindow;//Insert a value into the associative array
  26.  
  27. mcWindow.mcWindowBackground.onPress = function():Void {
  28. this._parent.swapDepths(nTopDepth);//swap the selected window with the current top depth to bring it to the front
  29. this._parent.startDrag();//target the window background, then its parent to add a drag function onPress
  30. };
  31. mcWindow.mcWindowBackground.onRelease = function():Void {
  32. this._parent.stopDrag();//target the window background, then its parent to remove a drag function onRelease
  33. };
  34. mcWindow.mcWindowBackground.onReleaseOutside = mcWindow.mcWindowBackground.onRelease;
  35.  
  36. mcWindow.mcCloseSquare.onRelease = function():Void {
  37. delete oOpenedWindows[sLinkage]//remove the window from the array on close
  38. this._parent.removeMovieClip();//remove the movie clip when you press the close button.
  39. };
  40. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.