-1

Good day all,

I m new to actionscript3 , and I cant solve few problems on my code. The first problem is glowfilter is not run. According to my research glowfilter 's alpha is set like that but , when ı click true answer it do not response. But the ı try algorithm ıt enter the right case. The second problem is I want to define write answer as global but when ı changed the rightAnswer in a function it is not change,how can ı over this problem ? I think defining global variable in actionscript is different from c .

Thank you for your help and sorry for my bad english!

<s:Button id="answer1" width="388" height="68" label="" cornerRadius="16"
              fontFamily="Georgia" fontSize="17" click="checkanswers(1)">
        <s:filters>
            <mx:GlowFilter id="answer1_glow" color="0x00ff00" alpha="0" strength="3"/>
            <mx:GlowFilter id="answer1_glow2" color="0xff0000" alpha="0" strength="3"/>
        </s:filters>
    </s:Button>
    <s:Button id="answer2" width="388" height="68" label="" cornerRadius="16"
              fontFamily="Georgia" fontSize="17" click="checkanswers(2)">
        <s:filters>
            <mx:GlowFilter id="answer2_glow" color="0x00ff00" alpha="0" strength="3"/>
            <mx:GlowFilter id="answer2_glow2" color="0xff0000" alpha="0" strength="3"/> 
        </s:filters>
    </s:Button>
    <s:Button id="answer3" width="388" height="68" label="" cornerRadius="16"
              fontFamily="Georgia" fontSize="17" click="checkanswers(3)">
        <s:filters>
            <mx:GlowFilter id="answer3_glow" color="0x00ff00" alpha="0" strength="3"/>
            <mx:GlowFilter id="answer3_glow2" color="0xff0000" alpha="0" strength="3"/>
        </s:filters>
    </s:Button>
    <s:Button id="answer4" width="388" height="68" label="" cornerRadius="16"
              fontFamily="Georgia" fontSize="17"  click="checkanswers(4)">
        <s:filters>
            <mx:GlowFilter id="answer4_glow" color="0x00ff00" alpha="0" strength="3"/>
            <mx:GlowFilter id="answer4_glow2" color="0xff0000" alpha="0" strength="3"/>
        </s:filters>
    </s:Button>

</s:VGroup>
<fx:Script>
    <![CDATA[
        import flash.events.TimerEvent;
        import flash.utils.Timer;

        import mx.controls.Alert;
        import mx.events.FlexEvent;

        import mx.core.FlexGlobals;
        import mx.events.FlexEvent;

        private var baseTimer:int;
        private var t:Timer;
        private const TIMER_INTERVAL:Number = 10;


        public var rightAnswer:int = 0 ;     // ---> ı want to use a global rightAnswer .

        public function checkanswers(answer:int):void{
        trace("answer is " + answer );  
        trace("rightanswer is " + rightAnswer);
               if ( answer == rightAnswer) {
                       switch (answer) {
                       case 1 :
                          answer1.label = "green"; 
                          answer1.alpha = 1;  // ı want to change glowfilters alpha in there.
                           break;
                       case 2 :
                          answer2.label = "green"; 
                          answer2_glow.alpha = 1; 
                           break;
                       case 3 :
                           answer3.label = "green"; 
                          answer3_glow.alpha = 1; 
                           break;
                       case 4 :
                           answer4.label = "green"; 
                          answer4_glow.alpha = 1;  
                           break;
                       default :

                           break;
                   }
             } 
               else{
                   switch (answer) {
                       case 1 :
                           answer1.label = "red";
                           answer1_glow2.alpha = 1; 
                           break;
                       case 2 :
                           answer2.label = "red";
                           answer2_glow2.alpha = 1.0; 
                           break;
                       case 3 :
                           answer3.label = "red;
                           answer3_glow2.alpha = 1.0; 
                           break;
                       case 4 :
                           answer4.label = "red";
                           answer4_glow2.alpha = 1.0;  
                           break;
                       default :

                           break; 

               }

                   switch (rightAnswer) {
                       case 1 :
                           answer1.label = "green"; 
                           answer1_glow.alpha = 1; 
                           break;
                       case 2 :
                           answer2.label = "green"; 
                           answer2_glow.alpha = 1; 
                           break;
                       case 3 :
                           answer3.label = "green"; 
                           answer3_glow.alpha = 1; 
                           break;
                       case 4 :
                           answer4.label = "green"; 
                           answer4_glow.alpha = 1;  
                           break;
                       default :

                           break;
                   }

               }               
}              

        public function application1_creationCompleteHandler(event:FlexEvent):void
        {
            // TODO Auto-generated method stub
            soru.text = " En büyük kim ?";
            answer1.label = "Galasaray";
            answer2.label = "Bursaspor";
            answer3.label = "Beşiktaş";
            answer4.label = "Fenerbahçe";
            var rightAnswer:int = 2;
            trace(" rightAnswer fonkideki " + rightAnswer); 
        }

    ]]>
</fx:Script>
ketan
  • 19,129
  • 42
  • 60
  • 98
  • rightAnswer is set to 0 in your code so no matter what you click on it will never evaluate to true – The_asMan Sep 11 '13 at 14:55
  • even if ı didnt set to 0 , ıt is automatically set to 0. but I changed my code as a when every new question comes from an array , ı want to assign new value of rightAnswer to global variable rightAnswer, but even in the basic when ı call the question preparing function ı need to change value of public var rightAnswer:int . – user2769027 Sep 11 '13 at 15:42
  • my point exactly I will write an answer for you in a minute – The_asMan Sep 11 '13 at 18:27

1 Answers1

0

You issue is with variable scope, it is not doing what you think it is doing.
When you use keyword "var" you re creating a new variable in the current scope.
In this case you are trying to assign 2 to the class level variable "rightAnswer" when in fact you are creating a new variable called "rightAnswer" scoped to function level.

    public function application1_creationCompleteHandler(event:FlexEvent):void
    {
        // TODO Auto-generated method stub
        soru.text = " En büyük kim ?";
        answer1.label = "Galasaray";
        answer2.label = "Bursaspor";
        answer3.label = "Beşiktaş";
        answer4.label = "Fenerbahçe";
        var rightAnswer:int = 2; // <<<<--- right here is your problem
        trace(" rightAnswer fonkideki " + rightAnswer); 
    }

So instead do this.

    public function application1_creationCompleteHandler(event:FlexEvent):void
    {
        // TODO Auto-generated method stub
        soru.text = " En büyük kim ?";
        answer1.label = "Galasaray";
        answer2.label = "Bursaspor";
        answer3.label = "Beşiktaş";
        answer4.label = "Fenerbahçe";
        var rightAnswer:int = 12345678; // <<<<--- right here is your problem
        this.rightAnswer = 2; // <<<<--- here is your correction
        trace(" rightAnswer class level" + this.rightAnswer);
        trace(" rightAnswer function level" + rightAnswer);// << -- this can only be accessed inside of the current function


    }
The_asMan
  • 6,364
  • 4
  • 23
  • 34