We help IT Professionals succeed at work.

How to change the states in Adobe Flex 3

bogdan_raduta
on
636 Views
Last Modified: 2013-11-11
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

Comment
Watch Question

where have you define the state 'est'?

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

Author

Commented:
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

Commented:
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.

Author

Commented:
shmeltex, can you please tell me how can I import it?

Commented:
You need to add one more import statement below package { line with other import statements in InfoWindowTabbedComponent2.as file like this:
import TabExamples;

Author

Commented:
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

Commented:
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.

Author

Commented:
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

Author

Commented:
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.

Author

Commented:
Later edit: Seems that there`s no way for sending PM`s or editing a post.
Can I send you an email or something?

Commented:
Bogdan,

Send the password to shmeltex at asdasd.ru

Author

Commented:
Done
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Commented:
Bogdan,

Add an argument to function changeState and it should do the trick:
public function changeState( e:Event ):void

Author

Commented:
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.

Author

Commented:
He really deserve more points because he`s the only one who helped me.

Commented:
Thank you for kind words! Glad to help!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.