Changing states with actionScript

Hi,
I have some states set up in my app using MXML as per the
script sample below. This is of course very handy, but upon
changing from one state to another I want to include some
actionScript to make a few things happen when the state changes. I
know that I have full control over states in AS but can I set up
the states as below using MXML and then use AS just to perform the
change. Currently, selecting a new item in a dataGrid calls the
change (change="currentState='editProperty'") but I'd prefer to
have this (change="editProperty()") which would call an AS function
to do some work and *then* change the state. Any help appreciated
as usual,
<!-- States -->
<mx:states>
<!-- Edit property state (multipage form)-->
<mx:State name="editProperty">
<mx:SetProperty target="{props}" name="height"
value="262"/>
<mx:SetProperty target="{props}" name="x"/>
<mx:AddChild position="lastChild">
<mx:VBox width="100%" height="100%">
-- various controls etc. here --
</mx:VBox>
</mx:AddChild>
</mx:State>
</mx:states>
cheers,
Mike

You could write an actionscript method which takes any class
that extends UIComponent. This includes Application, Canvas, Panel,
etc...
All have a current state
I actually have some code which does just that
package com.domain.ecommerce.admin
import mx.events.ItemClickEvent;
import mx.controls.Alert;
import mx.core.UIComponent;
public class StateManager
* changes the current state based on anything that will
generate an ItemClickEvent...
* For exmaple: <mx:LinkBar
itemClick="StateManager.chooseState(targetComponent,event)" >
... </mx:LinkBar>
* note: this is the object the link bar is located in ...
public static function chooseState(component:UIComponent,
event:ItemClickEvent) : void {
component.currentState = event.label;
public static function
chooseStateByString(component:UIComponent, newState:String) : void
component.currentState = newState;
You can do something like :
click="StateManager.chooseStateByString(this, 'newState');"

Similar Messages

  • Change state with MenuBar component

    It's pretty easy to change the state with a button. Example:
    click="currentState='AboutScreen'"
    But when I try to do this on the MenuBar component, I'm not
    having any luck. When I click on the item (let's say Help ->
    About), nothing happens. My code is:
    click="currentState='menu.student.create_profile'"
    I also tried,
    itemClick="currentState='menu.student.create_profile'"
    No luck.. anyone know how to change states based off items
    clicked from the MenuBar?

    This should get you started:
    http://www.playingwithfire.com/fun.html

  • Change States with Hyperlink

    I would like to be able to change states in a Flex WindowedApplication by clicking on a RichEditableText hyperlink or some form of clickable text.  Is there a way to do this?  Thanks.

    Hi Bruyn,
    I didn't quite understand your page, but from your text it
    seems you want Spry URLUtils (
    http://labs.adobe.com/technologies/spry/samples/data_region/DataWithURLParams.html)
    I did both things on my page, notably on a gallery as well,
    even though it's much simpler than the one you have (
    http://www.cosmicollective.org/gallery.html?row=0).
    From there the gallery will automatically load the row
    fetched from the URL of the user's browser. You only need to edit
    the number on the link that corresponds to the data you want to
    display.
    Cheers,
    Tomas

  • Add states with ActionScript, because MXML states occupying space

    I have my States setup with MXML fine, but I noticed that even though the State is not currently set, it is occupying space and leaving a huge empty gap in my layout.
    I want the State to not occupy the space when it is not the active State.
    I think using ActionScript to dynamically add the State when it is needed will solve the problem. What is the ActionScript code to add States (to replace all the State MXML code below)?
    <mx:Labe text="No State should be visible and don't occupy any space" />
    <mx:states>
    <mx:State name="{displayThisState}">
    <mx:AddChild>
    </mx:AddChild>
    </mx:State>
    </mx:states>
    Thanks.

    I'll recommend you to use a ViewStack instead of States, States in Fx 3 are kinda diffucult to declare and manage as your app grows. Fortunately in the Flex SDK 4 there will be a much simpler syntax to declare states.

  • Change state with timer as well as with mouse click?

    I would like to set up an image with two states, "State 1" and "State 2"
    I would like the button to toggle between "State 1" and "State 2" onMouseDown.
    But I would also like the button to alternate between "State 1" and "State 2" on its own every 3 seconds.
    Can you tell me how to set this up?

    This should get you started:
    http://www.playingwithfire.com/fun.html

  • Can I change state with textfield?

    Hello Everyone,
    I would like to be able to change a state as soon as the user
    types some thing in a text field. I have the change event wired up
    the text field. I am able to show Alert box whenever the text filed
    gets click. But when I set state to be loaded, I am unable to load
    the state.
    Can you guys help me, please.

    got it working:
    this.currentState = 'xxx';

  • Changing states with a timer?

    Does Flex support any state changes based on a timer? I can't find anything online about this.

    Setup the Timer something like this...
       import flash.utils.Timer;
       import flash.events.TimerEvent;
       // create a timer which fires every second (1000 ms)
       var timer:Timer = new Timer( 1000 );
      // add a listener to the timer
       timer.addEventListener( TimerEvent.TIMER, handleTimerEvent );
       // start the timer
       timer.start();
    Then change the state in the timer event handler...
       public function handleTimerEvent( event:TimerEvent ):void
           this.currentState = "nextState";
    Does that help?
    Ben Edwards

  • PSD Rollover Button with image in front stops button from changing state

    I have a wide PSD button that changes state when rolled over. I would like to place a PNG image with transparency in some areas over the top of it so that the rollover button shows through the transparent areas of the PNG.
    How can you get it to do the rollover effect when the user mouses over the bit of the button that the image is in front of? Is ther a way of making the PNG 'invisible' to the mouse?
    I know I could redesign the button so that it includes the image but I'm trying to keep file sizes and load times to a minimum, I use this button a lot on my website with a different on each, and having that number of individual buttons would result in a bloated, slow-loading website.

    Hi Abhishek
    Thanks for your reply. I was able to achieve the effect I wanted by having the PNG and the PSD Button with the same link and then grouping them. This means I can mouse over the PNG and still get the PSD rollover effect, which is perfect.
    However I also have another similar problem. I have some different PSD Rollover Buttons which have some text in front of them (basically it's the button label). On some of these buttons when you roll over the text it prevents the rollover state of the button, and on other buttons the rollover effect occurs as it should, and there doesn't appear to be any consistency about which does what. Grouping or ungrouping doesn't appear to make a difference. Can you help?

  • Changing mxml UIComponents with Actionscript

    Hello,
    i´m searching about a way to change the text of labels createtd with Designer by Actionscript. But i try to browse the entire collection to find all used UI-Components.
    If i use the debugger, i can see  an mxmlContent Array with all Components but i can´t use theses in Actionscript.
    Regards
    Thomas

    Hi David,
    thanks for the reply, but that is not, what i want.
    I´m searching about a solution to browse the complete mxml component list in Actionscript.
    We will change the labels of all items by runtime with data from a cfc (Coldfusion component) without hard coding the labels in Actionscript. I need a readable collection of all UI-Components to read the id´s, comparinge these with the cfc datasource and change these with other data from this source.
    As i say, the Applipcation.mxmlContent (or any Group.mxmlContent) has all these properties. Baut i can´t use mxmlContent in Flashbuilder because i got an error, that this property is not defined instead i can read that in the debugger.
    Thomas

  • Change the "Font size" in a TLF Textfield with actionscript?

    I could not realize how should I resize my TLF Textfiels in flash cs6 with actionscript??
    None of these worked:
    if (....)
         myTLFText.textSize++;
         myTLFText.fontSize++;
    Error: Access of possibly undefined property size through a reference with static type fl.text:TLFTextField.
    I appreciate your kind help please??

    Here is the part of code I am using to resize the textfield (and other elements).
    /******SET POSITION**********/
    function setPosition():void
          //Position appBG
          appBG.height = stage.stageHeight;
          appBG.width = appBG.height;
          //Fit the appTXT in middle of screen  (AppTXT is a MovieClip contains sourceText - RTLTextField)
          appTXT.sourceText.width = stage.stageWidth * 0.9;
          appTXT.sourceText.x = stage.stageWidth * 0.05;
          appTXT.sourceText.y = stage.stageHeight * 0.1;
          //Fit the maskText layer on top of text;
          maskText.width = appTXT.sourceText.width;
          maskText.height = stage.stageHeight * 0.8;
          maskText.x = stage.stageWidth * 0.05;
          maskText.y = stage.stageHeight * 0.1;
          //Set buttons in their proper position
          if (stage.stageWidth > stage.stageHeight)
                appBG.width = stage.stageWidth;
                appBG.height = appBG.width;
          appBG.x = stage.stageWidth / 2;
          appBG.y = stage.stageHeight / 2;
    Everything works fine, but when I install the apk on my Google nexus (800x1280), the font size looks VERY SMALL and I can hardly read it!
    If I increase the Font size pt (Red Arrow in above PrntScr) to 40. then it reads perfect on phones with 800x1280 screen size. Ok?  But then any OTHER smaller screen cell phones will see the font TOO BIG!
    So I need to set the Font size pt by CODE based on a percent of stageWidth to could solve this. thx.

  • Can't access object using "id" or "name" if created with actionscript

    How can you register an instance of an object with actionscript so that it's id or name value is accessible?
    I included a simple example where a Button is created using mxml and in the same way it is created using actionscript.  The actionscript object is inaccessible using it's "id" and "name" property.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                   creationComplete="application1_creationCompleteHandler(event)">
        <fx:Script>
            <![CDATA[
                import mx.events.FlexEvent;
                protected function application1_creationCompleteHandler(event:FlexEvent):void
                    import spark.components.Button;
                    var asBtn:Button = new Button();
                    asBtn.label = "actionscript";
                    asBtn.x = 200;
                    asBtn.id = "asButton";
                    asBtn.name = "asButtonName";
                    addElement(asBtn);
                    trace("mxmlButton="+this["mxmlButton"].label); // returns: mxml  label
                    //trace("mxmlButton="+this["asButton"].label); // returns runtime error: ReferenceError: Error #1069: Property asButton not found on TestId and there is no default value.
                    //trace("mxmlButton="+this["asButtonName"].label); // returns runtime error: ReferenceError: Error #1069: Property asButtonName not found on TestId and there is no default value.
            ]]>
        </fx:Script>
        <s:Button
            id="mxmlButton"
            label="mxml label"
            alpha="0.8"/>
    </s:Application>

    Hi Dan,
    It is a very rare occurrence when I miss not being able to access an object (object property, really) using the ["name"] notation for objects created using actionscript.
    In MXML the compiler is conveniently adding an attribute to the class with the same name as the id, so you can conveniently refer to it using the [] notation. While we explicitly specify an application container to use, the MXML compiler creates a custom container which is a derivative of the base container and to that it adds properties for the children declared in MXML. I guess it also effectively calls "addElement" for us when  the container is being constructed.
    Your example assumes that using "addElement" to add the button to the application container is the same as declaring a variable (ie property ). It isn't, so there's no point in looking for an property of the name "as3Button" using the [] notation, because it doesn't exist. The container is managing a collection of children in it's display list and that's not the same as being accessible as properties of the container.
    Generally speaking, accessing properties using the ["name"] syntax isn't necessary.
    Paul
    [edit: you may wonder why "addElement" doesn't conveniently also add the "id" attribute to be an property of the container class. Unfortunately, it can't because the container class would need to be dynamic and it's not. A further complication would be that adding properties at runtime would invite naming clashes at runtime with associated mayhem. MXML can do this because the compiler generates the class and can trap name duplication at compile time.
    Great question, BTW.
    -last edit changed my "attributes" to be "properties" in line with Adobe's terminology]

  • Changing states from within a component

    Let's say that I have a TileList that is rendering data in a
    VBox. Eventually the TileList fills up and starts scrolling. I want
    to change states when clicking on item in the TileList.
    I don't want to place the click-attribute in the TileList,
    because it will change states when I am scrolling the list without
    actually selecting anything.
    I want to say click="currentState='state2'" inside the VBox,
    but that does not work because state2 is at the root level, and I
    don't know how to get to the root-level (in lack of a better word)
    from withing the component.
    This is not the proper syntax, so misunderstand me the right
    way here... Is there an equivallence to
    click="currentState='_root.state2'" in mxml?
    Thanks for any suggestions or best practices. I want the easy
    way out.
    This is the general structure...
    <mx:Application>
    <mx:states>
    <mx:State id="state1"/>
    <mx:State id="state2"/>
    <mx:State id="state3"/>
    </mx:states>
    <mx:TileList dataprovider="{...}">
    <mx:itemRenderer>
    <mx:component>
    <mx:VBox id="ClickThisBoxToChangeStates">
    <mx:Image/>
    <mx:Label/>
    </mx:Vbox>
    </mx:component>
    </mx:itemRenderer>
    </mx:TileList>
    </mx:Application>

    Your assumption is right.
    It doesn't work because there is no state2-state defined
    within the mx:component.
    In the documentation about changing states it says that I can
    go from application level and change states within a component;
    like this: click="currentState='mycomponent.anotherstate'" but not
    how I can change a state at application level from within a state.
    When I try, it says (at runtime) that the state is not defined.
    So I don't know why <mx:VBox
    click="currentState='state2'"/> doesn't work.
    I apprechiate your expertese a lot.

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • How to change state of a constraint from DEFERABLE to IMMEDIATE?

    Hi,
    I am runnig 10gR2 and would like to change state of a constraint from
    DEFERABLE to IMMEDIATE without recreating it.
    The change is working at the session level with
    SET CONSTRAINT <constraint name> IMMEDIATE;
    But this is not visible for other users.
    So my question is, if there is any other way to do it, so the change would be visible for every user.
    Here is what I have done:
    CREATE TABLE TEST_TBL
    ID NUMBER
    ALTER TABLE TEST_TBL ADD CONSTRAINT pk_test_tbl PRIMARY KEY(ID)
    INITIALLY DEFERRED DEFERRABLE;
    SQL> INSERT INTO test_tbl VALUES(1);
    1 row created.
    SQL> INSERT INTO test_tbl VALUES(1);
    1 row created.
    SQL> INSERT INTO test_tbl VALUES(1);
    1 row created.
    SQL> COMMIT;
    COMMIT
    ERROR at line 1:
    ORA-02091: transaction rolled back
    ORA-00001: unique constraint (TEST_SCHEMA.PK_TEST_TBL) violated
    The constraint is checked only at commit,
    To change this:
    SQL> SET CONSTRAINT pk_test_tbl IMMEDIATE;
    Constraint set.
    SQL> INSERT INTO test_tbl VALUES(1);
    1 row created.
    SQL> INSERT INTO test_tbl VALUES(1);
    INSERT INTO test_tbl VALUES(1)
    ERROR at line 1:
    ORA-00001: unique constraint (TEST_SCHEMA.PK_TEST_TBL) violated
    But if I would connect with user B, I would be able to do multiple inserts with value 1.
    Thanks

    I am runnig 10gR2 and would like to change state of a constraint from
    DEFERABLE to IMMEDIATE without recreating it.From Oracle Constraints:
    Note: A non-deferrable constraint is generally policed by a unique index (a unique index is created
    unless a suitable index already exists). A deferrable constraint must be policed by a non-unique index
    (as it's possible for a point of time during a transaction for duplicate values to exist). This is why
    it is not possible to alter a constraint from non-deferrable to deferrable. Doing so would require
    Oracle to drop and recreate the index.
    A PK enforces uniqueness procedurally without relying on a unique index. The main advantage
    of a non-unique index is the constraint can be disabled and re-enabled without the index being dropped and recreated.

  • Animating a button with actionScript

    I'm fairly stumped on this one - but probably quite simple to fix.
    I need to animate the scale of a button with actionScript 2.0. I've inherited a project that was done with actionScript 2.0 and have decided to stay with this generation rather than rewrite the whole project. Anyway - I've created a sound object, it plays audio from the library and 3 seconds after it starts playing, I want to animate the "next" button and make it pulse to attract the users attention.
    Doing this by putting the button in a movie clip is not working as I am losing it's button states and besides it's probably far more tighter to program it.
    When the user rolls over the button it stops pulsing but still retains it's up, over and down states.
    Any easy answer?

    Thanks for your help Ned.
    I ended up making an advanced button with movie clips and using programming for all the states.
    Movies are so much easier to control than buttons.
    But you have raised something I had overlooked...setTimeout( )
    I was using setInterval( ) and then doing clearInterval( ) within the function so it would only loop once, which of course was problematic if the user beat the 'clearInterval' code by clicking on the button too early.
    Actually used setInterval( ) to delay all sound on the project - now going to re-program all that.
    Thanks

Maybe you are looking for

  • F110 Paying Company Code AP vs AR

    Collegues, We have configured a payer company code diferent than a sender company code for Payment Program (F110). The issue here is that we need this scenario only for AP, but not for AR. AP should "centralize" outgoing payments from one single comp

  • Analog Dial-up access with RSA

    I have few question about it, 1) Is it required ACS to cisco to work with RSA ? 2) Any link to good document ? Thank a lot

  • Table behind tax details in P.O

    Hi, im trying to find the tax condition types in a purchase order by going to item detail(invoice tab) ->taxes button and it displays the taxes . i'm unable to find the table where the tax conditon type , amount and the conditon value are being store

  • OS X 10.5.4 Combined Update Installation Hang

    I can't seem to install the 10.5.4 combined update. When I try, it hangs before log in. It goes to "Configuring Installation" but never finishes. Is there a way to install this update? I am on a Macbook.

  • Registering QuicktimePro in Vista 64

    How does one register my QuickTime Pro key when using Vista 64? Not like XP.???