flash - Referring stage from the class Action Script 3 -


basically coding switch between scenes clicking buttons. giving frame label sand scene names arguments. movieclip(root).gotoandstop(framelabel, scenename); works fine on stage. when use same on class throws warning typeerror: error #1009: cannot access property or method of null object reference. know happens there no root class.is there way fix it. please find code below.

//class code

package {     import flash.events.keyboardevent;     import flash.events.mouseevent;     import flash.display.simplebutton;     import flash.display.*;     import flash.text.*;      import flash.events.event;     import flash.display.movieclip;      public class clickbutton extends simplebutton {     public var flabel:string;     public var sname:string;     public var snumber:number;      public function clickbutton()     {      }          public function gotosession(sesbut:simplebutton, framelabel:string, scenename:string):void {                sesbut.addeventlistener(mouseevent.click, gotoses);              function gotoses(event:mouseevent):void {            movieclip(root).gotoandstop(framelabel, scenename);     }     } } 

//as3 code

var btn1 = new clickbutton(); addchild(btn1); btn1.gotosession(home, "menu", "home"); 

you have 2 problems here, , don't understand why work but,

1 : when try compile code, compile time error :

there miss "}" @ end of class.

i removed what's not used:

package {     import flash.events.mouseevent;     import flash.display.simplebutton;     import flash.display.movieclip;     public class clickbutton extends simplebutton {         public function clickbutton() {         }         public function gotosession(sesbut:simplebutton,framelabel:string,scenename:string):void {             sesbut.addeventlistener(mouseevent.click,gotoses);             function gotoses(event:mouseevent):void {                 movieclip(root).gotoandstop(framelabel,scenename);                // , if want remove clickbutton instance :;                // add 2 lines :                sesbut.removeeventlistener(mouseevent.click,gotoses);                movieclip(root).removechild(sesbut);                // not forget remove listeners before remove instance!             }         }     } } 

i suppose have button in library linked clickbutton class here below:

enter image description here

so :

var btn1:clickbutton = new clickbutton(); addchild(btn1); btn1.gotosession(btn1, "menu", "home"); stop(); 

if click on btn1, brings me scene "home" @ label "menu".

this works charm.

on framelabel "menu" :

stop(); trace("currentscene.name = " + this.currentscene.name); trace("currentframelabel = " + this.currentframelabel);  /* output :  currentscene.name = home currentframelabel = menu */ 

[edit]

if set visibility false, again true, have same problem if want change alpha property of mc_1. works on file:

import flash.display.movieclip; stop(); trace("currentscene.name = " + this.currentscene.name); trace("currentframelabel = " + this.currentframelabel); var mc_1:movieclip = mc_1; // if don't add line, have same problem when set visibility true var mc_2:movieclip = mask_mc; var mc_3:movieclip = red_mc; // same mc_2 labeled "mask_mc" // mc_1 recognized movieclip mc2. mc_1.visible = false; mc_1.visible = true; // no more problem if add line var mc_1:movieclip = mc_1; // if don't this, cannot access mc_1 movieclip mc_1.alpha = 0.5; mc_1.mask = mc_2; mc_3.alpha = 0.5; mc_3.visible = false; mc_3.visible = true; mc_3.alpha = 0.9; // seems have declare mc variables before change properties 

[/edit]

but don't understand line :

//btn1.gotosession(home, "menu", "home"); 

home null (you don't have reference clickbutton named home)...???


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -