Link to home
Start Free TrialLog in
Avatar of bogdan_raduta
bogdan_radutaFlag for Romania

asked on

How to change the states in Adobe Flex 3

Hello,

I`m really new to Flex and ActionScript so please be patient with me.

I want to implement this script: http://gmaps-samples-flash.googlecode.com/svn/trunk/demos/TabNavigatorInfoWindow /srcview/index.html

...that is doing this "magic": http://gmaps-samples-flash.googlecode.com/svn/trunk/demos/TabNavigatorInfoWindow /TabNavigatorInfoWindow.html#


...but I want to tweak it a little on InfoWindowTabbedComponent. To be more precise I`m trying to insert buttons in that tab, and when you click one the state will change.

I don`t know why my code is not working...you can see it in the attachment.

 
package { 
import flash.events.Event;
import flash.events.MouseEvent; 
import mx.containers.Panel;
import mx.containers.TabNavigator;
import mx.containers.VBox;
import mx.controls.Button;
import mx.core.UIComponent;
 
public class InfoWindowTabbedComponent2 extends UIComponent 
{ 
            
  public function InfoWindowTabbedComponent2() {
    // Add body text
    var tabNavigator:TabNavigator = new TabNavigator();
    tabNavigator.width = 290;
    tabNavigator.height = 150;
     //Here I`m creating 3 tabs inside TabNagivator
    tabNavigator.addChild(createTab("Utile"));
    tabNavigator.addChild(createTab("Cultura"));
    tabNavigator.addChild(createTab("Istorie"));
    tabNavigator.addChild(createTab("Link")); 
    
    
    addChild(tabNavigator);
    addChild(createTab("Parent")); 
    
    cacheAsBitmap = true;
  }
  
  //Change state function
 public function changeState():void 
  {
      currentState = "est";     
  }
  
  //Create a tab inside TabNavigator
  public function createTab(label:String):VBox 
  {
  	var tab:VBox = new VBox();
  	tab.label = label;
  	var inside:Panel = new  Panel();
  	var link:Button;
  	  	  	
  	inside.width = 280;
  	inside.height = 100;
  	inside.setStyle("borderStyle", "none");
  	
	//If the user clicks the Link tab and inside that it will click the button, the state must change
  	if (label=="Link")
  		{
  		link = new Button;
  		link.id = "lnkGoogle";
	  	link.label = "Google";
	  	
	  	link.addEventListener(MouseEvent.CLICK, changeState);
	  	
		//add the button to the tab
		inside.addChild(link);
		
		//add the tab to the TabNavigator
		tab.addChild(inside);
  	
  	return tab;
  }
} 
}

Open in new window

Avatar of Gary Benade
Gary Benade
Flag of South Africa image

where have you define the state 'est'?

if it's in the parent of this container, you could try:
parent.currentState = 'est';
Avatar of bogdan_raduta

ASKER

Thank you for your answer but is not working. I`m getting this error: 1119: Access of possibly undefined property currentState through a reference with static type flash.display:DisplayObjectContainer.

As you can see in the image attached, the "est" state is the start state and the "test" state is the one with the problem.

1.PNG
Avatar of shmeltex
shmeltex

Let's say your mxml file named TabExample.mxml (I can't see the name of the file on the image) then instead of parent.currentState, do TabExample.currentState. Don't forget to add import for TabExample.
shmeltex, can you please tell me how can I import it?
You need to add one more import statement below package { line with other import statements in InfoWindowTabbedComponent2.as file like this:
import TabExamples;
After I added this function (my mxml is called "TabNavigatorInfoWindow."):
 public function changeState():void  {   TabNavigatorInfoWindow.currentState = 'est';      }

I`m getting this error: 1119: Access of possibly undefined property currentState through a reference with static type Class.

Let me remind you (I don`t know if it helps) that this function along with that script posted on
my first comment are located in a ".as" file. Do you want me to attach the full project? Maybe it will more easier for you to to help me.

Thank you,
Bogdan
Bogdan,

Just to make sure, you do have "import TabNavigatorInfoWindow;" statement in .as file? If you do have it and still getting error, please post TabNavigatorInfoWindow.mxml.
Shmeltex,

Is not working so I uploaded my project on my server(here I can`t upload password protected files, and I don`t want it to be available to the public)


The address: www.epic.droopy.ro/project.zip
The password is: exp-exch
I changed the password because someone just told me that this discussion can be viewed even if you don`t have an account here. I have sent you the new password.
Later edit: Seems that there`s no way for sending PM`s or editing a post.
Can I send you an email or something?
Bogdan,

Send the password to shmeltex at asdasd.ru
Done
ASKER CERTIFIED SOLUTION
Avatar of shmeltex
shmeltex

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, but it still doesn`t work. I changed everything you said, but when I`m clicking the button from that Tab, the state is not changing.

I have uploaded the new source, maybe you can see if there`s something wrong.
Link:www.epic.droopy.ro/projectNew.zip
The password is the same.

Thank you again for helping me.
Bogdan,

Add an argument to function changeState and it should do the trick:
public function changeState( e:Event ):void
It worked! Thank you so much! You deserve more than 500 points, because you`re the only one from the whole internet who helped me. I didn`t find the answer not even in adobe forums.

Thank you again, I can`t express how happy I am.
He really deserve more points because he`s the only one who helped me.
Thank you for kind words! Glad to help!