TextArea scrolling pauses timerEvent

60 Views Asked by At

I have a TimerEvent that makes a shape's alpha change every second:

private function changeLightStatus(e:TimerEvent):void{
    if (boolFlashOn == false){
        light.alpha = 1;
        boolFlashOn = true;
    }else{
        light.alpha = 0.5;          
        boolFlashOn = false;
    }

No issues, it works fine, but I have a <s:TextArea/> underneath and when the user scrolls it the timer pauses and the shape stops flashing.

I've had a look at other questions and the answers say to make a new time thread so that they aren't connected, but apparently I can't do this in Flash Builder (Correct me if I'm wrong).

Thanks in advance

2

There are 2 best solutions below

3
VC.One On

I've updated your tags to include Flex, but unfortunately I only ever use pure AS3 (no Flex tags).

So while you wait for a better answer you could try...

(1)
When you addChild(light), also set as: light.mouseChildren = light.mouseEnabled = false;.

(2)
Otherwise consider EnterFrame instead of Timer:

//# add to initial setup of vars...
var counter:int = 0;
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);

Then add supporting function

private function onEnterFrame (e:Event) : void
{
    if ( count >= 50)
    {
        if (boolFlashOn == false)
        { light.alpha = 1; boolFlashOn = true; }

        else
        { light.alpha = 0.5; boolFlashOn = false; }

        count = 0; //reset for next loop
    }

    count++
}

Let me know how it goes...

1
O.B On

As an alternative to using a text Area I made this:

<s:Group width="{this.width*0.8}" height="{this.height*0.175}" top="{this.height*0.475}" horizontalCenter="0">
    <s:Rect left="0" right="0" top="0" bottom="0">
        <s:fill>
            <s:SolidColor color="0xFFFFFF"/>
        </s:fill>
    </s:Rect>
    <s:Scroller>
        <s:Group width="{this.width*0.8}" height="{this.height*0.175}" top="{this.height*0.475}" horizontalCenter="0">  
            <s:Label id="lblInfo" color="0x000000" width="{this.width*0.8}"/>
        </s:Group>
    </s:Scroller>
</s:Group>

This made a very basic box where the user can scroll through text and wouldn't affect my timerEvent.

I would still like to know the reason why the textArea pauses the timeline. I made a very simple example:

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[

        private var tmrTest : Timer = new Timer(100);
        private var boolTest : Boolean = false;

        private function init():void{

            tmrTest.addEventListener(TimerEvent.TIMER, testChange)
            tmrTest.start();
        }

        private function testChange(e:TimerEvent):void{
            if (boolTest == false){
                btnTest.label = "Bye";
                boolTest = true;
            }else{
                btnTest.label = "Hi";
                boolTest = false;
            }
        }

    ]]> 
</fx:Script>

<s:Button id="btnTest" label="Hi" width="{this.width*0.5}" height="{this.height*0.1}"/>

<s:Group width="{this.width*0.8}" height="{this.height*0.175}" top="{this.height*0.475}" horizontalCenter="0">
    <s:Rect left="0" right="0" top="0" bottom="0">
        <s:fill>
            <s:SolidColor color="0xFFFFFF"/>
        </s:fill>
    </s:Rect>
    <s:Scroller>
        <s:Group width="{this.width*0.8}" height="{this.height*0.175}" top="{this.height*0.475}" horizontalCenter="0">  
            <s:Label color="0x000000" width="{this.width*0.8}"
                     text="{'a\nb\nc\nd\ne\nf\ng'}"/>
        </s:Group>
    </s:Scroller>
</s:Group>

<s:TextArea width="{this.width*0.8}" height="{this.height*0.175}" top="{this.height*0.725}" horizontalCenter="0" editable="false"
            text="{'a\nb\nc\nd\ne\nf\ng'}"/>

I probably should have mentioned before that this was running it on an iPhone, not a simulator. The simulator didn't give me any problems and I haven't tried android.