Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rating: Thread Rating: 13 votes, 5.00 average. Display Modes
Old 10-15-2010, 05:47 PM   #1
philipp37
Registered User
 
Join Date: Oct 2010
Posts: 4
Default Error 1061: Call to a possibly undefined method...

Hello everyone. Could you please look over my code below to figure out why I'm getting the following two errors:


1061: Call to a possibly undefined method setSelection through a reference with static type mx.core:ITextInput. line 477 Flex Problem

and

1119: Access of possibly undefined property selectionBeginIndex through a reference with static type mx.core:ITextInput. line 419 Flex Problem


Heres the affected portion of my code called AutoComplete.as:

Code:
package myWidgets.ParcelNotificationWidget
{
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.net.SharedObject;
import flash.ui.Keyboard;
import mx.core.UIComponent;
import mx.controls.ComboBox;
import mx.collections.ArrayCollection;
import mx.collections.ListCollectionView;

-----------------------------------

/**
	 *  @private
	 */
	override protected function commitProperties():void
	{
	    super.commitProperties();
		
  	    if(!dropdown)
			selectedIndex=-1;
  			
	    if(dropdown)
		{
		    if(typedTextChanged)
		    {
			    cursorPosition = textInput.selectionBeginIndex;

				updateDataProvider();

			    //In case there are no suggestions there is no need to show the dropdown
  			    if(collection.length==0 || typedText==""|| typedText==null)
  			    {
  			    	dropdownClosed=true;
			    	showDropdown=false;
  			    }
				else
				{
					showDropdown = true;
					selectedIndex = 0;
 		    	}
 		    }
		}
	}
		
	/**
	 *  @private
	 */
	override protected function focusOutHandler(event:FocusEvent):void
	{
		super.focusOutHandler(event)
 		if(keepLocalHistory && dataProvider.length==0)
 			addToLocalHistory();
	}
	/**
	 *  @private
	 */
	override public function getStyle(styleProp:String):*
	{
		if(styleProp != "openDuration")
			return super.getStyle(styleProp);
		else
		{
	     	if(dropdownClosed)
	     		return super.getStyle(styleProp);
     		else
     			return 0;
		}
	}
	/**
	 *  @private
	 */
	override protected function keyDownHandler(event:KeyboardEvent):void
	{
	    super.keyDownHandler(event);

	    if(!event.ctrlKey)
		{
		    //An UP "keydown" event on the top-most item in the drop-down
		    //or an ESCAPE "keydown" event should change the text in text
		    // field to original text
		    if(event.keyCode == Keyboard.UP && prevIndex==0)
			{
	 		    textInput.text = _typedText;
			    textInput.setSelection(textInput.text.length, textInput.text.length);
			    selectedIndex = -1; 
			}
		    else if(event.keyCode==Keyboard.ESCAPE && showingDropdown)
			{
	 		    textInput.text = _typedText;
			    textInput.setSelection(textInput.text.length, textInput.text.length);
			    showingDropdown = false;
			    dropdownClosed=true;
			}
			else if(event.keyCode == Keyboard.ENTER)
			{
 				if(keepLocalHistory && dataProvider.length==0)
					addToLocalHistory();
 			}
			else if(lookAhead && event.keyCode ==  Keyboard.BACKSPACE 
			|| event.keyCode == Keyboard.DELETE)
			    removeHighlight = true;
	 	}
	 	else
		    if(event.ctrlKey && event.keyCode == Keyboard.UP)
		    	dropdownClosed=true;
	 	
 	    prevIndex = selectedIndex;
	}
	
	/**
	 *  @private
	 */
	override protected function measure():void
	{
	    super.measure();
	    measuredWidth = mx.core.UIComponent.DEFAULT_MEASURED_WIDTH;
	}

	/**
	 *  @private
	 */
	override protected function updateDisplayList(unscaledWidth:Number, 
						      unscaledHeight:Number):void
	{
		
	    super.updateDisplayList(unscaledWidth, unscaledHeight);
		
		//An UP "keydown" event on the top-most item in the drop 
		//down list otherwise changes the text in the text field to ""
  	    if(selectedIndex == -1)
	    	textInput.text = typedText;

	    if(dropdown)
		{
		    if(typedTextChanged)
			{
			    //This is needed because a call to super.updateDisplayList() set the text
			    // in the textInput to "" and thus the value 
			    //typed by the user losts
  			    if(lookAhead && showDropdown && typedText!="" && !removeHighlight)
				{
					var label:String = itemToLabel(collection[0]);
					var index:Number =  label.toLowerCase().indexOf(_typedText.toLowerCase());
					if(index==0)
					{
					    textInput.text = _typedText+label.substr(_typedText.length);
					    textInput.setSelection(textInput.text.length,_typedText.length);
					}
					else
					{
					    textInput.text = _typedText;
					    textInput.setSelection(cursorPosition, cursorPosition);
					    removeHighlight = false;
					}
						
				}
			    else
				{
				    textInput.text = _typedText;
				    textInput.setSelection(cursorPosition, cursorPosition);
				    removeHighlight = false;
				}
			    
			    typedTextChanged= false;
			}
		    else if(typedText)
		    	//Sets the selection when user navigates the suggestion list through
		    	//arrows keys.
				textInput.setSelection(_typedText.length,textInput.text.length);
		}
 	    if(showDropdown && !dropdown.visible)
 	    {
 	    	//This is needed to control the open duration of the dropdown
 	    	super.open();
	    	showDropdown = false;
 	    	showingDropdown = true;

 	    	if(dropdownClosed)
	 	    	dropdownClosed=false;
 	    }
	}
	

	/**
	 *  @private
	 */
	override protected function textInput_changeHandler(event:Event):void
	{
	    super.textInput_changeHandler(event);
	    //Stores the text typed by the user in a variable
	    typedText=text;
	}

THANKS A LOT!!!!!!!!
philipp37 is offline   Reply With Quote
Old 10-15-2010, 09:00 PM   #2
EightySeven
Senior Member
 
Join Date: Aug 2008
Posts: 134
Default

I'm going to take a stab in the dark on this one since no one else has responded yet.

Getting a "through a reference with static type" error means what you are trying to access is a Static variable/function. To access these you need to use the class name like

ActionScript Code:
public class Enemy extends Sprite {     static public function changeCostume(newCostume:Sprite):void     {         //someCode     } } //To access this from outside I would use Enemy.changeCostume(newcostume); //Not myEnemy.changeCostume(newCostume);

So try using:

ITextInput.setSelection(int, int);

I've never used ITextInput but this looks like it would be the issue.
EightySeven is offline   Reply With Quote
Old 10-15-2010, 10:23 PM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,833
Send a message via Skype™ to henke37
Default

Nope, your guess is completly wrong.

Static properties can be accessed from instance references too.

The real error is that the compiler says that the reference type used does not have the property that he tried to use. It could potentionaly be assigned a reference to an object that does have it, but that's not likely and is definitly not guranteed.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 10-16-2010, 03:44 PM   #4
philipp37
Registered User
 
Join Date: Oct 2010
Posts: 4
Default

Thanks guys! The fix was actually to import spark.components.ComboBox rather than the mx version of the ComboBox.
philipp37 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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:46 AM.

///
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.