Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Switch Case Statement Help...

Guest
May 26, 2011 May 26, 2011

Hello,

I am trying to get my pages through Case Statement But...

Can any one Help me.. here is my code..

This is my Buttons Code... My buttons are on 1st Frame of My FLA..

stop(); btn1.addEventListener(MouseEvent.CLICK, varTest); btn2.addEventListener(MouseEvent.CLICK, varTest2); function varTest(event:MouseEvent):void {      var page = 1;      gotoAndStop(20); } function varTest2(event:MouseEvent):void {      var page = 2;      gotoAndStop(20); }

and this is my 20th frame code. (here I'm checking variable)

import flash.events.Event; addEventListener(Event.ENTER_FRAME,checkCaseMe); function checkCaseMe(event:Event) {      switch (page)      {           case "1" :                info_txt.text = "page1";                break;           case "2" :                info_txt.text = "page1";                break;           default :                info_txt.text = "page00";      } }

When I test the movie.. Error Occured (Scene 1, Layer 'Actions', Frame 21, Line 6 1120: Access of undefined property page. )

Can Anyone help please.. How do I correct this....???

Thanks...

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 26, 2011 May 26, 2011

If the error really is that code, then the problem is that you are declaring page inside a function, which limits its scope to within the function(s).  Try the following instead...

stop();

var page:uint; btn1.addEventListener(MouseEvent.CLICK, varTest); btn2.addEventListener(MouseEvent.CLICK, varTest2); function varTest(event:MouseEvent):void {      page = 1;      gotoAndStop(20); } function varTest2(event:MouseEvent):void {      page = 2;      gotoAndStop(20); }

Translate
LEGEND ,
May 26, 2011 May 26, 2011

That error is pointing to frame 21, so what code do you have on line 6 in frame 21?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2011 May 26, 2011

If the error really is that code, then the problem is that you are declaring page inside a function, which limits its scope to within the function(s).  Try the following instead...

stop();

var page:uint; btn1.addEventListener(MouseEvent.CLICK, varTest); btn2.addEventListener(MouseEvent.CLICK, varTest2); function varTest(event:MouseEvent):void {      page = 1;      gotoAndStop(20); } function varTest2(event:MouseEvent):void {      page = 2;      gotoAndStop(20); }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 26, 2011 May 26, 2011

Dear Ned Murphy,

Now Error is not coming.. but its not working.... when I add (var page:uint;) error gone and event it never go to frame 20???.

Thanks.. if you can help more...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2011 May 26, 2011

You should learn to use the trace() function to help you troubleshoot code yourself.  In each of your button functions include:

trace("btn clicked"); // will help you know for sure that the buttons are working

And in frame 20, you should add a trace as well to determine whether you actually get there when you think you don't...

trace("in frame 20");

Lastly, your code for frame 20 is likely not what you need for a couple of reasons...

1) If you think the ENTER_FRAME listener is used to detect/trigger when the timeline enters a frame, that is not what it does.  What it does is continually process the function that it calls at the frame rate of the file.  It is normally only used when you want to repeatedly trigger some functionality.

2)  If you assign number values to the page variable, you do not want to use String values in your cases.

All you should need in frame 20 is...

switch (page)
{
     case 1 :
          info_txt.text = "page1";
          break;
     case 2 :
          info_txt.text = "page1";
          break;
     default :
          info_txt.text = "page00";
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 27, 2011 May 27, 2011

Thanks Bro.. Thanks a lot for your detailed reply... It’s really a lot helpful to me.. I did exactly what you said.. its now working fine... Yes now I’m using trace.. and its good to check the things…

Thanks for your time…..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 27, 2011 May 27, 2011
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines