actionscript 3 - AS3 Check if variable is String outputs MouseEvent info -


update: found workaround using different code. leaving question in cause wants answer why happening , maybe can else well. thanks


i trying check if variable string, in case if has url in string. code executing , in trace statement this:

if (thewebsite string) trace(thewebsite); 

output: [mouseevent type="click" bubbles=true cancelable=false eventphase=3 localx=2259.8671875 localy=2485.85205078125 stagex=1003.25 stagey=71 relatedobject=null ctrlkey=false altkey=false shiftkey=false buttondown=false delta=0 commandkey=false controlkey=false clickcount=0] mainstage? [object main_activate] , website? [mouseevent type="click" bubbles=true cancelable=false eventphase=3 localx=2259.8671875 localy=2485.85205078125 stagex=1003.25 stagey=71 relatedobject=null ctrlkey=false altkey=false shiftkey=false buttondown=false delta=0 commandkey=false controlkey=false clickcount=0]

here code creates variable.

1.

menuscreen.one_btn.addeventlistener(mouseevent.click, webviewbutton("http://www.mywebsite.com")); 

2.

public function webviewbutton(thewebsite:string):function  {             trace("made here: " + thewebsite); /// output: www.mywebsite.com             return function(e:mouseevent):void {                 trace("made here too: " + thewebsite); //output: www.mywebsite.com             removemenuscreen(thewebsite);             }         } 

3.

public function removemenuscreen(thewebsite:string = null, e: event = null) {              if (thewebsite string) {                 trace("but did make here? " + thewebsite);                 // outputs above code mentioned earlier.              } 

i using function other things why set way. how can fix have code execute if defined string? tips.

the code posted not produce output posted.

what would produce "[mouseevent ...]" output if had addeventlistener(mouseevent.click, removemenuscreen). why? because mouseevent coerced string value since removemenuscreen handler's first parameter thewebsite of type string.

so, answer question: it is being executed when thewebsite string. , only ever string, or null, otherwhise if coercion string not possible throw runtime error.

if want avoid runtime coercion, make parameter untyped:

public function removemenuscreen(thewebsite:* = null) {     if (thewebsite string) {         trace("but did make here? " + thewebsite);     } else if (thewebsite mouseevent) {         trace("or did make here?", thewebsite)     } } 

i don't recommend go down path, though, because adds lot of unclarity, leads bugs , hard debugging.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -