A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Problems With NumericStepper in Flash CS3

  1. #1
    Senior Member
    Join Date
    Jun 2009
    Posts
    101

    Thumbs up Problems With NumericStepper in Flash CS3

    Hello Friends,

    I need a small help. I just strucked up with NumericStepper issue.

    I have a NumericStepper and i am setting the Minimum value to 0 & Maximum value to 10. Now my requirement is, suppose if the user entered/typed the value which is greater than Maximum value (ie 10) inside NumericStepper inputbox I want to display that particular value in "RED" color. how to do this.

    Your help would be appreciated, i need a solution asap.
    I am attaching the code what i am doing.......


    package
    {
    import fl.controls.Label;
    import fl.controls.NumericStepper;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.text.*;

    public class NumericStepperExample extends Sprite
    {
    private var ns1:NumericStepper;
    private var ns2:NumericStepper;
    private var lbl1:Label;
    private var lbl2:Label;
    private var rowHeight1:Number = 100;
    private var rowHeight2:Number = 50;

    public function NumericStepperExample() {
    setupSteppers();
    setupLabels();
    }

    private function setupLabels():void {
    lbl1 = new Label();
    lbl1.text = "Min Value -- 0 and Max Value -- 10";
    lbl1.autoSize = TextFieldAutoSize.LEFT;
    lbl1.move(200, rowHeight1);
    addChild(lbl1);
    }

    private function setupSteppers():void {
    ns1 = new NumericStepper();
    ns1.stepSize = 1;
    ns1.minimum = 0;
    ns1.maximum = 10;
    ns1.width = 60;
    ns1.move(100, rowHeight1);
    ns1.addEventListener(Event.CHANGE, changeOccurred);
    addChild(ns1);

    }

    private function changeOccurred(e:Event):void {
    var nsTarget:NumericStepper = e.target as NumericStepper;

    var redColor:TextFormat = new TextFormat();
    redColor.color = 0xff0000;

    var blackColor:TextFormat = new TextFormat();
    blackColor.color = 0x000000;

    if (nsTarget.value > nsTarget.maximum) {
    nsTarget.setStyle("textFormat", redColor);
    } else {
    nsTarget.setStyle("textFormat", blackColor)
    }
    }
    }
    }

    Rajesh

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is one way of doing that. nm is the NumericStepper.
    PHP Code:
    import flash.events.Event;
    nm.minimum 0;
    nm.maximum 5;
    nm.textField.textField.addEventListener (Event.CHANGEcHandler);

    function 
    cHandler (event:Event):void
    {
        if (
    int(event.currentTarget.text) > nm.maximum)
        {
            
    event.currentTarget.htmlText "<font color='#FF0000'>"+event.currentTarget.text+"</font>";
        }

    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Jun 2009
    Posts
    101

    Thumbs up

    Hello cancerinform,

    Thank you so much for your reply. This is what i am looking for. Can you please do a favor for me.

    can you please provide me the same solution in Flex 3. actually i have to implement this in flex. sorry to inform you late. i am new to flex 3.

    waiting for your reply.
    Rajesh

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I think with Flex 3 it is not possible, because of the mx components. However, with Flashbuilder 4 it works.
    PHP Code:
    <?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">

        <fx:Script>
            <![CDATA[
                import spark.components.TextInput;
                private var myText:TextInput;
                protected function numstepActivater(event:Event):void
                {
                    myText = nm.textDisplay;
                    myText.addEventListener(Event.CHANGE, cHandler);
                }
                private function cHandler(event:Event):void
                {
                    if (int(myText.text) > nm.maximum)
                    {
                        nm.setStyle("color",0xFF0000);
                    }
                    else
                    {
                        nm.setStyle("color",0x000000);
                    }
                }
            ]]>
        </fx:Script>
        <s:NumericStepper id="nm" x="50" y="50" minimum="0" maximum="5" add="numstepActivater(event)"/>
    </s:Application>
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center