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

Calling member functions of symbols

New Here ,
Jul 04, 2020 Jul 04, 2020

I'm trying to make an easily reusable button object for navigating to different frames in my main timeline.   So after importing the object you would only need this one line of code, calling the updateButton member function to change the label text and target frame for the button:

this.myButton3.updateButton(2, "Continue")

 

The following code is included in frame 1 of a Movie Clip object, with instance name myButton3.   (To attach javascript, I wrapped this Movie Clip around a basic button with instance name baseButton)

//update button used for navigation
this.updateButton = function(targetFrameNum, newText, visibility = true){ 
	this.visible = visibility; 
	this.baseButton.label.text = newText;	
	this.addEventListener("click", function(){exportRoot.gotoAndPlay(targetFrameNum - 1)}.bind(exportRoot), {once: true});  //only clickable once.
}.bind(this);

 

Unfortunately I am having issues with calling updateButton from the main timeline.  I think the function is not declared until after the 1st frame of myButton3 executes, so I am getting errors about this.myButton3.update() being undefined. 

Is there a better way to declare the updateButton member function to make it easily callable from the main timeline?

TOPICS
Other
160
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
Community Expert ,
Jul 05, 2020 Jul 05, 2020
LATEST

wait until the needed object exists (eg, by putting this.myButton3.etc in a function called from the timeline/frame where this.updateButton is defined).

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