Skip to main content
Participant
July 5, 2020
Question

Calling member functions of symbols

  • July 5, 2020
  • 1 reply
  • 175 views

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?

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 5, 2020

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).