Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
Old 07-05-2005, 12:03 PM   #1
hzahid777
Registered User
 
Join Date: Jul 2005
Posts: 1
Default Problem creating a draggable navigation menu with dynamic buttons

Dear All,

I am trying to create a draggable navigation menu in which the menu items are dynamic. For the time being the text of the menu items is stored in a script variable as comma seperate values.

The buttons are created within a movieclip which is created on the _root object. So far it works fine. But the moment I add the code to make the button container movie clip draggable, the buttons lose their mouse interactivity. The buttons no more respond to mouse events like onRollOver, onRollOut etc.

Attached is the code that I used:

ActionScript Code:
//setProperty("btndyn.swf", _x, "600"); stop(); // // Color for button text. //nbrBtnTextColor = 0xFFCC99; nbrBtnTextColor = 0x000000; nbrBtnTextColorOver = 0xCCCCCC; // Size for text on button. nbrBtnTextSize = 12; // Color for button background in UP state. nbrBtnClrUp = 0x006699; // Color for button in OVER state. nbrBtnClrOv = 0x000066; // Color for button in deactivated state ("you are here" indication). nbrBtnClrOff = 0x999999; // Space between buttons. nbrBtnGutter = 3; // Button interior margins. nbrBtnMrgLeft = 2; nbrBtnMrgRight = 2; nbrBtnMrgTop = 1; nbrBtnMrgBottom = 1; btnMinWidth = 88; btnMinHeight = 15; // ==================================================================== // Create TextFormat for button textfields tfmBtnText = new TextFormat(); tfmBtnText.align = "left"; tfmBtnText.color = nbrBtnTextColor; // See library for font object and it's linkage properties. tfmBtnText.font = "Arial"; tfmBtnText.size = nbrBtnTextSize; // Create TextFormat for button mouseover textfields tfmBtnTextOver = new TextFormat(); tfmBtnTextOver.align = "left"; tfmBtnTextOver.color = nbrBtnTextColorOver; // See library for font object and it's linkage properties. tfmBtnTextOver.font = "Arial"; tfmBtnTextOver.size = nbrBtnTextSize; // ==================================================================== // Delimited string of all button text. stgBtnText = "About Us|Design|Our Work"; // Split above string to an array. rraBtnText = stgBtnText.split("|"); // ==================================================================== // Create navigation container clip (makes moving the whole thing around a lot easier). _root.createEmptyMovieClip("mvcNav", 0); //mvcNav._x = 10; //mvcNav._y = 10; //mvcNav.createEmptyMovieClip("navContainer", 1); //_root.createEmptyMovieClip("navContainer", 0); /* navContainer.onPress = function(){     startDrag(this) }; navContainer.onRelease = function(){     stopDrag(); } */ //navContainer.setMask("menu.png"); // ==================================================================== // Loop to create buttons and all interior objects. for (icrBtn=0; icrBtn<rraBtnText.length; icrBtn++) {     // Create clip to hold button and reference to it (saves on typing and redundant concatenation).     rfcBtn = mvcNav.createEmptyMovieClip("mvcBtn"+icrBtn, 0);     // Store button's number inside button's own timeline (used later).     rfcBtn.nbrID = icrBtn;     // Create textfield at depth of 2, so background and outlines can go under it.     rfcBtn.createTextField("tfdBtn", 2, nbrBtnMrgLeft, nbrBtnMrgTop, 1, 1);     // Create reference to textfield (can't be done on single line, like movieclips).     rfcTfd = rfcBtn.tfdBtn;     // Apply textformat to textfield.     rfcTfd.setNewTextFormat(tfmBtnText);     // Set textfield properties, including text to display.     rfcTfd.autoSize = "left";     rfcTfd.embedFonts = true;     rfcTfd.selectable = false;     // Assign text from array to textfield in button.     rfcTfd.text = rraBtnText[icrBtn];     //     // Calculate button width & height based on current dimensions     // (dimensions of textfield) plus interior margins.     nbrBtnW = nbrBtnMrgLeft+rfcBtn._width+nbrBtnMrgRight;     nbrBtnH = nbrBtnMrgTop+rfcBtn._height+nbrBtnMrgBottom;         if(nbrBtnW < btnMinWidth)         nbrBtnW = btnMinWidth;             if(nbrBtnH < btnMinHeight)         nbrBtnH = btnMinHeight;             //     // Create internal clip to contain visual background, to serve as both hit area     // and to be available for color change in response to button events. /*     rfcBkgd = rfcBtn.createEmptyMovieClip("mvcBtnBkgd", 0);     rfcBkgd.moveTo(0, 0);     rfcBkgd.beginFill(nbrBtnClrUp);     rfcBkgd.lineTo(nbrBtnW, 0);     rfcBkgd.lineTo(nbrBtnW, nbrBtnH);     rfcBkgd.lineTo(0, nbrBtnH);     rfcBkgd.lineTo(0, 0);     rfcBkgd.endFill();     // Create color object for background clip so color can be changed with button actions.     rfcBkgd.clrMe = new Color(rfcBkgd); */      //     // This section optional -------------------------------------------------     // just creates clip to contain lines that simulate highlites and shadows around button rectangle     // (these don't change color -- just the background). /*      rfcBvl = rfcBtn.createEmptyMovieClip("mvcBvl", 1);     rfcBvl.moveTo(0, 0);     rfcBvl.lineStyle(1, 0xFFFFFF);     rfcBvl.lineTo(nbrBtnW, 0);     rfcBvl.lineStyle(1, 0x000000);     rfcBvl.lineTo(nbrBtnW, nbrBtnH);     rfcBvl.lineTo(0, nbrBtnH);     rfcBvl.lineStyle(1, 0xFFFFFF);     rfcBvl.lineTo(0, 0);     rfcBvl.endFill(); */      // -----------------------------------------------------------------------     //     //Move button clip to appropriate position if 2nd or later button.     rfcBtn._x = 10;     //if (icrBtn)        {         rfcBtn._y = _root.mvcNav["mvcBtn"+(icrBtn-1)]._y+_root.mvcNav["mvcBtn"+(icrBtn-1)]._height+nbrBtnGutter;     }     //     // Establish button actions.     rfcBtn.onRollOver = function() {         //this.mvcBtnBkgd.clrMe.setRGB(_root.nbrBtnClrOv);         this.tfdBtn.setTextFormat(tfmBtnTextOver);         //trace(this.tfdBtn.text);     };         rfcBtn.onRollOut = function() {         //this.mvcBtnBkgd.clrMe.setRGB(_root.nbrBtnClrUp);         //trace(this.tfdBtn.text);         this.tfdBtn.setTextFormat(tfmBtnText);     };         rfcBtn.onPress = function() {         // On press, launch the fncBtnPress function and pass it the identity of the button         _root.fncBtnPress(this.nbrID);         //trace(this.nbrID);     }; } fncBtnPress = function (nbrButtonID) {     //_root.rfcBtnLast.mvcBtnBkgd.clrMe.setRGB(nbrBtnClrUp);     _root.rfcBtnLast.enabled = true;     var rfcBtn = _root.mvcNav["mvcBtn"+nbrButtonID];     _root.rfcBtnLast = rfcBtn;     //rfcBtn.mvcBtnBkgd.clrMe.setRGB(nbrBtnClrOff);     rfcBtn.enabled = false;     // Switch statement to act based upon numeric identity of button that called this function.     // Actions go on lines just after the comment lines "do whatever".     switch (nbrButtonID) {     case 1 :         // Portfolio         // do whatever         break;     case 2 :         // Gallery         // do whatever         break;     case 3 :         // History         // do whatever         break;     case 4 :         // Profile         // do whatever         break;     case 5 :         // Links         // do whatever         break;     case 6 :         // Contact         getURL("mailto:[email protected]");         break;     default :         // Home         // do whatever     } };


Please if someone could help me solve this problem as its a high priority for me.

regards,
Husain
hzahid777 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:25 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.