Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Location
    Houston, Texas
    Posts
    1

    Default Combo Box - Newbie

    I bought a web template and am currently trying to modify the combo box in the flash header. I was able to change the list of items in the combo box but now I need to link each item to a different web page when it is selected from the combo box. Can someone tell me what part of the code I need to modify to have each item link to a seperate page? This is the action script that was already associated with that flash component:

    Code:
    #initclip 3
    /*
    
    		FComboBoxClass
    		EXTENDS FScrollSelectListClass
    		
    		This class manages a "pulldown" scrolling list.
    
    */
    
    function FComboBoxClass()
    {
    	_global._popUpLevel = (_global._popUpLevel==undefined) ? 20000 : _global._popUpLevel+1;
    	
    	// Testing for _root's existence?
    	this.superHolder = _root.createEmptyMovieClip("superHolder" + _popUpLevel, _popUpLevel);
    	var testContainer = this.superHolder.createEmptyMovieClip("testCont", 20000);
    	var testBox = testContainer.attachMovie("FBoundingBoxSymbol", "boundingBox_mc", 0);
    	
    	if (testBox._name==undefined) {
    		// _root doesn't exist. 
    		this.superHolder.removeMovieClip();
    		this.superHolder = this._parent.createEmptyMovieClip("superHolder" + _popUpLevel, _popUpLevel);
    	} else {
    		testContainer.removeMovieClip();
    	}
    	
    	if (this.rowCount==undefined) {
    		this.rowCount=8;
    		this.editable = false;
    	}
    
    	this.itemSymbol = "FComboBoxItemSymbol";
    	this.init();
    	this.permaScrollBar = false;
    	this.proxyBox_mc.gotoAndStop(1);
    	this.width = this._width;
    	this.height =this.proxyBox_mc._height*this._yscale/100;
    	
    	for &#40;var i=0; i<this.labels.length; i++&#41; &#123;
    		this.addItem&#40;this.labels&#91;i&#93;, this.data&#91;i&#93;&#41;;
    	&#125;
    	this.lastSelected = 0;
    	this.selectItem&#40;0&#41;;
    	this._xscale = this._yscale = 100;
    	this.opened = false;
    	this.setSize&#40;this.width&#41;;
    	this.highlightTop&#40;false&#41;;
    	if &#40;this.changeHandler.length>0&#41; &#123;
    		this.setChangeHandler&#40;this.changeHandler&#41;;
    	&#125;
    	this.onUnload = function&#40;&#41;
    	&#123;
    		this.superHolder.removeMovieClip&#40;&#41;;
    	&#125;
    
    	this.setSelectedIndex&#40;0, false&#41;;
    	this.value = "";
    	this.focusEnabled = true;
    	this.changeFlag = false;
    &#125;
    
    FComboBoxClass.prototype = new FScrollSelectListClass&#40;&#41;;
    
    Object.registerClass&#40;"FComboBoxSymbol", FComboBoxClass&#41;;
    
    
    
    // &#58;&#58;&#58; PUBLIC METHODS
    
    
    FComboBoxClass.prototype.modelChanged = function&#40;eventObj&#41;
    &#123;
    	super.modelChanged&#40;eventObj&#41;;
    	var event = eventObj.event;	
    	if &#40;event=="addRows" || event=="deleteRows"&#41; &#123;
    		var diff = eventObj.lastRow - eventObj.firstRow + 1;
    		var mode = &#40;event=="addRows"&#41; ? 1 &#58; -1;
    		var len = this.getLength&#40;&#41;;
    		var lenBefore = len-mode*diff;
    		if &#40;this.rowCount>lenBefore || this.rowCount>len&#41; &#123;
    			this.invalidate&#40;"setSize"&#41;;
    		&#125;
    		if &#40;this.getSelectedIndex&#40;&#41;==undefined&#41; &#123;
    			this.setSelectedIndex&#40;0, false&#41;;
    		&#125;
    	&#125; else if &#40;event=="updateAll"&#41; &#123;
    		this.invalidate&#40;"setSize"&#41;;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.removeAll = function&#40;&#41;
    &#123;
    	if &#40;!this.enable&#41; &#123;
    		return;
    	&#125;
    	super.removeAll&#40;&#41;;
    	if &#40;this.editable&#41; this.value="";
    	this.invalidate&#40;"setSize"&#41;;
    &#125;
    
    
    FComboBoxClass.prototype.setSize = function&#40;w&#41;
    &#123;
    	if &#40;w==undefined || typeof&#40;w&#41;!="number" || w<=0 || !this.enable&#41; &#123;
    		return;
    	&#125;
    	this.proxyBox_mc._width = w;
    	this.container_mc.removeMovieClip&#40;&#41;;
    	this.measureItmHgt&#40;&#41;;
    	
    	this.container_mc = this.superHolder.createEmptyMovieClip&#40;"container", 3&#41;;
    	
    	this.container_mc.tabChildren = false;
    	this.setPopUpLocation&#40;this.container_mc&#41;;
    	this.container_mc.attachMovie&#40;"FBoundingBoxSymbol", "boundingBox_mc", 0&#41;;
    	this.boundingBox_mc = this.container_mc.boundingBox_mc;
    	this.boundingBox_mc.component = this;
    	this.registerSkinElement&#40;this.boundingBox_mc.boundingBox, "background"&#41;;
    	this.proxyBox_mc._height = this.itmHgt;
    	
    	this.numDisplayed = Math.min&#40;this.rowCount, this.getLength&#40;&#41;&#41;;
    	if &#40;this.numDisplayed<3&#41; &#123;
    		this.numDisplayed = Math.min&#40;3, this.getLength&#40;&#41;&#41;;
    	&#125;
    	this.height = this.numDisplayed * &#40;this.itmHgt-2&#41; + 2;
    	super.setSize&#40;w, this.height&#41;;
    
    	this.attachMovie&#40;"DownArrow", "downArrow", 10&#41;;
    	this.downArrow._y = 0;
    	this.downArrow._width = this.itmHgt;
    	this.downArrow._height = this.itmHgt;
    	this.downArrow._x = this.proxyBox_mc._width-this.downArrow._width;
    	this.setEditable&#40;this.editable&#41;;
    	this.container_mc._visible = this.opened;
    	this.highlightTop&#40;false&#41;;
    	
    	this.fader = this.superHolder.attachMovie&#40;"FBoundingBoxSymbol", "faderX", 4&#41;;
    	this.registerSkinElement&#40;this.fader.boundingBox, "background"&#41;;
    	this.fader._width = this.width;
    	this.fader._height = this.height;
    	this.fader._visible = false;
    
    &#125;
    
    FComboBoxClass.prototype.setDataProvider = function&#40;dp&#41;
    &#123;
    	super.setDataProvider&#40;dp&#41;;
    	this.invalidate&#40;"setSize"&#41;;
    	this.setSelectedIndex&#40;0&#41;;
    &#125;
    
    
    FComboBoxClass.prototype.getValue = function&#40;&#41;
    &#123;
    	if &#40;this.editable&#41; &#123;
    		return this.fLabel_mc.getLabel&#40;&#41;;
    	&#125; else &#123;
    		return super.getValue&#40;&#41;;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.getRowCount = function&#40;&#41;
    &#123;
    	return this.rowCount;
    &#125;
    
    FComboBoxClass.prototype.setRowCount = function&#40;count&#41;
    &#123;
    	this.rowCount = &#40;this.getLength&#40;&#41;>count&#41; ? Math.max&#40;count,3&#41; &#58; count;
    	this.setSize&#40;this.width&#41;;
    	var len = this.getLength&#40;&#41;;
    	if &#40;len-this.getScrollPosition&#40;&#41;<this.rowCount&#41; &#123;
    		this.setScrollPosition&#40;len-&#40;Math.min&#40;this.rowCount, len&#41;&#41;&#41;;
    		this.invalidate&#40;"updateControl"&#41;;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.setEditable = function&#40;editableFlag&#41;
    &#123;
    	if &#40;!this.enable&#41; return;
    	
    	this.editable = editableFlag;
    	if &#40;!this.editable&#41; &#123;
    		this.onPress = this.pressHandler;
    		this.useHandCursor = false;
    		this.trackAsMenu = true;
    		this.attachMovie&#40;"FComboBoxItemSymbol", "fLabel_mc", 5, &#123;controller&#58;this, itemNum&#58;-1&#125;&#41;;
    		this.fLabel_mc.onRollOver = undefined;
    		this.fLabel_mc.setSize&#40;this.width-this.itmHgt+1, this.itmHgt&#41;;
    		this.topLabel = this.getSelectedItem&#40;&#41;;
    		this.fLabel_mc.drawItem&#40;this.topLabel, false&#41;;
    		this.highlightTop&#40;false&#41;;
    	&#125; else &#123;
    		this.attachMovie&#40;"FLabelSymbol", "fLabel_mc", 5&#41;;		
    		this.fLabel_txt = this.fLabel_mc.labelField;
    		this.fLabel_txt.type = "input";
    		this.fLabel_txt._x = 4;
    		this.fLabel_txt.onSetFocus = this.onLabelFocus;
    		this.fLabel_mc.setSize&#40;this.width-this.itmHgt-3&#41;;
    		delete this.onPress;
    		this.fLabel_txt.onKillFocus = function&#40;&#41;
    		&#123;
    			this._parent._parent.myOnKillFocus&#40;&#41;;
    		&#125;
    		this.fLabel_mc.setLabel&#40;this.value&#41;;
    		this.fLabel_txt.onChanged = function&#40;&#41; &#123;
    				this._parent._parent.findInputText&#40;&#41;;
    		&#125;
    		this.downArrow.onPress = this.buttonPressHandler;
    		this.downArrow.useHandCursor = false;
    		this.downArrow.trackAsMenu = true;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.setEnabled = function&#40;enabledFlag&#41;
    &#123;
    	enabledFlag = &#40;enabledFlag == undefined || typeof&#40;enabledFlag&#41;!="boolean"&#41; ? true &#58; enabledFlag;
    	super.setEnabled&#40;enabledFlag&#41;;
    	this.registerSkinElement&#40;this.boundingBox_mc.boundingBox, "background"&#41;;
    	this.proxyBox_mc.gotoAndStop&#40; &#40;this.enable&#41; ? "enabled" &#58; "disabled"&#41;;
    	this.downArrow.gotoAndStop&#40; &#40;this.enable&#41; ? 1 &#58; 3&#41;;
    	if &#40;this.editable&#41; &#123;
    		this.fLabel_txt.type = &#40;enabledFlag&#41; ? "input" &#58; "dynamic";
    		this.fLabel_txt.selectable = enabledFlag;
    	&#125; else if &#40;enabledFlag&#41; &#123;
    		this.fLabel_mc.drawItem&#40;this.topLabel, false&#41;;
    		this.setSelectedIndex&#40;this.getSelectedIndex&#40;&#41;, false&#41;;
    	&#125;
    	this.fLabel_mc.setEnabled&#40;this.enable&#41;;
    	this.fLabel_txt.onSetFocus = &#40;enabledFlag&#41; ? this.onLabelFocus &#58; undefined;
    &#125;
    
    FComboBoxClass.prototype.setSelectedIndex = function&#40;index, flag&#41;
    &#123;
    	super.setSelectedIndex&#40;index, flag&#41;;
    	if &#40;!this.editable&#41; &#123;
    		this.topLabel = this.getSelectedItem&#40;&#41;;
    		this.fLabel_mc.drawItem&#40;this.topLabel, false&#41;;
    	&#125; else &#123; 
    		this.value = &#40;flag!=undefined&#41; ? "" &#58; this.getSelectedItem&#40;&#41;.label;
    		this.fLabel_mc.setLabel&#40;this.value&#41;;
    	&#125;
    	this.invalidate&#40;"updateControl"&#41;;
    &#125;
    
    FComboBoxClass.prototype.setValue = function&#40;value&#41;
    &#123;
    	if &#40;this.editable&#41; &#123;
    		this.fLabel_mc.setLabel&#40;value&#41;;
    		this.value = value;
    	&#125;
    &#125;
    
    // &#58;&#58;&#58; PRIVATE METHODS
    
    
    FComboBoxClass.prototype.pressHandler = function&#40;&#41;
    &#123;
    	this.focusRect.removeMovieClip&#40;&#41;;
    	if &#40;this.enable&#41; &#123;
    		if &#40;!this.opened&#41; &#123;
    			this.onMouseUp = this.releaseHandler;
    		&#125; else &#123;
    			this.onMouseUp = undefined;
    		&#125;
    		this.changeFlag = false;
    		if &#40;!this.focused&#41; &#123;
    			this.pressFocus&#40;&#41;;
    			this.clickFilter = &#40;this.editable&#41; ? false &#58; true;
    		&#125;
    		if &#40;!this.clickFilter&#41; &#123;
    			this.openOrClose&#40;!this.opened&#41;;
    		&#125; else &#123;
    			this.clickFilter = false;
    		&#125;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.clickHandler = function&#40;itmNum&#41; 
    &#123;
    	if &#40;!this.focused&#41; &#123;
    		if &#40;this.editable&#41; &#123;
    			this.fLabel_txt.onKillFocus = undefined;
    		&#125;
    		this.pressFocus&#40;&#41;;
    	&#125;
    	super.clickHandler&#40;itmNum&#41;;
    	this.selectionHandler&#40;itmNum&#41;;
    	this.onMouseUp = this.releaseHandler;
    &#125;
    
    FComboBoxClass.prototype.highlightTop = function&#40;flag&#41;
    &#123;
    	if &#40;!this.editable&#41; &#123;
    		this.fLabel_mc.drawItem&#40;this.topLabel, flag&#41;;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.myOnSetFocus = function&#40;&#41;
    &#123;
    	super.myOnSetFocus&#40;&#41;;
    	this.fLabel_mc.highlight_mc.gotoAndStop&#40;"enabled"&#41;;
    	this.highlightTop&#40;true&#41;;
    &#125;
    
    
    FComboBoxClass.prototype.drawFocusRect = function&#40;&#41;
    &#123;
    	this.drawRect&#40;-2,-2, this.width+4, this._height+4&#41;;
    &#125;
    
    FComboBoxClass.prototype.myOnKillFocus = function&#40;&#41;
    &#123;	
    	if &#40;Selection.getFocus&#40;&#41;.indexOf&#40;"labelField"&#41;!=-1&#41; return; // if the label is in focus, don't kill my focus!
    
    	super.myOnKillFocus&#40;&#41;;
    	delete this.fLabel_txt.onKeyDown;
    	this.openOrClose&#40;false&#41;;
    	this.highlightTop&#40;false&#41;;
    &#125;
    
    FComboBoxClass.prototype.setPopUpLocation = function&#40;mcRef&#41;
    &#123;
    	mcRef._x = this._x;
    	var point = &#123; x &#58; this._x, y &#58; this._y + this.proxyBox_mc._height&#125;;
    	this._parent.localToGlobal&#40;point&#41;;
    	mcRef._parent.globalToLocal&#40;point&#41;;
    	mcRef._x = point.x;
    	mcRef._y = point.y;
    	if &#40;this.height+mcRef._y>=Stage.height&#41; &#123;
    		this.upward = true;
    		mcRef._y = point.y-this.height - this.proxyBox_mc._height;
    	&#125; else &#123;
    		this.upward = false;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.openOrClose = function&#40;flag&#41;
    &#123;
    	if &#40;this.getLength&#40;&#41;==0&#41; return;
    	this.setPopUpLocation&#40;this.container_mc&#41;;
    	if &#40;this.lastSelected!=-1 && &#40;this.lastSelected<this.topDisplayed || this.lastSelected>this.topDisplayed+this.numDisplayed&#41;&#41; &#123;
    		super.moveSelBy&#40;this.lastSelected-this.getSelectedIndex&#40;&#41;&#41;;
    	&#125;
    	&#40;flag&#41; ? this.downArrow.gotoAndStop&#40;2&#41; &#58; this.downArrow.gotoAndStop&#40;1&#41;;	
    	if &#40;flag==this.opened&#41; &#123;
    		return ;
    	&#125;
    	
    	this.highlightTop&#40;!flag&#41;;
    	this.fadeRate = this.styleTable.popUpFade.value;
    	if &#40;!flag || this.fadeRate==undefined || this.fadeRate==0&#41; &#123;
    		this.opened = this.container_mc._visible = flag;
    		return;
    	&#125;
    
    	// code for fading in - depends on a prop called popUpFade. 
    	
    	this.setPopUpLocation&#40;this.fader&#41;;
    
    	this.time = 0;
    	this.const = 85 / Math.sqrt&#40;this.fadeRate&#41;;
    	this.fader._alpha = 85;
    	this.container_mc._visible = this.fader._visible = true;
    	this.onEnterFrame = function&#40;&#41;
    	&#123;
    		this.fader._alpha = 100 - &#40;this.const * Math.sqrt&#40;++this.time&#41; + 15&#41;;
     		if &#40;this.time>=this.fadeRate&#41; &#123;
    			this.fader._visible = false;
    			delete this.onEnterFrame;
    			this.opened = true;
    		&#125;
    	&#125;
    
    &#125;
    
    
    FComboBoxClass.prototype.fireChange = function&#40;&#41;
    &#123;
    	this.lastSelected = this.getSelectedIndex&#40;&#41;;
    	if &#40;!this.editable&#41; &#123;
    		this.topLabel = this.getSelectedItem&#40;&#41;;
    		this.fLabel_mc.drawItem&#40;this.topLabel, true&#41;;
    	&#125; else &#123;
    		this.value=this.getSelectedItem&#40;&#41;.label;
    		this.fLabel_mc.setLabel&#40;this.value&#41;;
    	&#125;
    	this.executeCallback&#40;&#41;;
    &#125;
    
    FComboBoxClass.prototype.releaseHandler = function&#40;&#41;
    &#123;
    
    	var onCombo = this.boundingBox_mc.hitTest&#40;_root._xmouse, _root._ymouse&#41;;
    	if &#40;this.changeFlag&#41; &#123;
    		if &#40;onCombo&#41; &#123;
    			this.fireChange&#40;&#41;;
    		&#125;
    		this.openOrClose&#40;!this.opened&#41;;
    	&#125; else if &#40;onCombo&#41; &#123;
    		this.openOrClose&#40;false&#41;;
    
    	&#125; else &#123;
    		this.onMouseDown = function&#40;&#41;
    		&#123;
    			if &#40;!this.boundingBox_mc.hitTest&#40;_root._xmouse, _root._ymouse&#41; && !this.hitTest&#40;_root._xmouse, _root._ymouse&#41;&#41; &#123;
    				this.onMouseDown = undefined;
    				this.openOrClose&#40;false&#41;;
    			&#125;
    		&#125;
    	&#125;
    	this.changeFlag=false;
    	this.onMouseUp=undefined;
    	clearInterval&#40;this.dragScrolling&#41;;
    	this.dragScrolling = undefined;
    &#125;
    
    FComboBoxClass.prototype.moveSelBy = function&#40;itemNum&#41;
    &#123;
    	if &#40;itemNum!=0&#41; &#123;
    		super.moveSelBy&#40;itemNum&#41;;
    		if &#40;this.editable&#41; &#123;
    			this.setValue&#40;this.getSelectedItem&#40;&#41;.label&#41;;
    		&#125;
    		if &#40;!this.opened&#41; &#123;
    			if &#40;this.changeFlag && !this.isSelected&#40;this.lastSelected&#41;&#41; &#123;
    				this.fireChange&#40;&#41;;
    			&#125;
    		&#125;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.myOnKeyDown = function&#40;&#41;
    &#123;
    	if &#40;!this.focused&#41; return ;
    	if &#40;this.editable && Key.isDown&#40;Key.ENTER&#41;&#41; &#123;
    		this.setValue&#40;this.fLabel_mc.getLabel&#40;&#41;&#41;;
    		this.executeCallback&#40;&#41;;
    		this.openOrClose&#40;false&#41;;
    	&#125; 
    	else if &#40; &#40;Key.isDown&#40;Key.ENTER&#41; || &#40;Key.isDown&#40;Key.SPACE&#41;&&!this.editable&#41;&#41; && this.opened&#41; &#123;
    		if &#40;this.getSelectedIndex&#40;&#41;!=this.lastSelected&#41; &#123;
    			this.fireChange&#40;&#41;;
    		&#125;
    
    		this.openOrClose&#40;false&#41;;
    		this.fLabel_txt.hscroll = 0;
    	&#125;
    	super.myOnKeyDown&#40;&#41;;
    &#125;
    
    
    FComboBoxClass.prototype.findInputText = function&#40;&#41;
    &#123;
    	if &#40;!this.editable&#41; &#123;
    		super.findInputText&#40;&#41;;
    	&#125;
    &#125;
    
    FComboBoxClass.prototype.onLabelFocus = function&#40;&#41;
    &#123;
    	this._parent._parent.tabFocused = false;
    	this._parent._parent.focused = true;
    	
    	this.onKeyDown = function&#40;&#41;
    	&#123;
    		this._parent._parent.myOnKeyDown&#40;&#41;;
    	&#125;
    	Key.addListener&#40;this&#41;;
    &#125;
    
    FComboBoxClass.prototype.buttonPressHandler = function&#40;&#41;
    &#123;	
    	this._parent.pressHandler&#40;&#41;;
    &#125;
    
    #endinitclip
    
    this.deadPreview._visible = false;
    [/code]

  2. # ADS
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    This is quite an extensive extension of the combo box component. I briefly scanned the code but I dont see a place where the change handler is called in association with a getURL command. I suggest making a test movie with a normal combobox to help understand how the change handler works. It may give you some insight into how it is being handled in the posted code sample.
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Combo box Actionscript
    By surajitkarmokar in forum Advanced Flash
    Replies: 2
    Last Post: 09-23-2008, 08:43 PM
  2. Combo Box Problem
    By ladz in forum Flash Scripting
    Replies: 6
    Last Post: 05-04-2006, 12:18 PM
  3. Replies: 1
    Last Post: 05-03-2006, 10:14 PM
  4. Combo Box Problem
    By ladz in forum Standalone & Applications
    Replies: 0
    Last Post: 04-29-2006, 09:54 AM
  5. Combo Box Help
    By mrtickle24 in forum Newbies
    Replies: 19
    Last Post: 11-30-2005, 09:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial