Bkf Posted January 19, 2016 Share Posted January 19, 2016 I have an instance of a button called myBtn on stage, and an instance of a square movie clip called myContainer- all of which published from flash.Within myContainer i have a movieclip instance named mySquare which is animated via classic tween from one point of the stage to another.When the stage is loaded i use this.myBtn.on("click", startBtnOnClick) to add an event listener to the button, and the function startBtnOnClick(evt) is indeed successfully called.What i'm trying to achieve is to tell myContainer to start playing when the button is clicked, and to do so i currently need to use:evt.target.parent.parent.myContainer.gotoAndPlay(0) which works, but doesn't seem to be a best practice here.What would be a more suitable approach? Perhaps i should dispatch a new event when the button is clicked and listen for it in the container? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted January 19, 2016 Share Posted January 19, 2016 Just keep a reference to `myContainer` somewhere else. The most naive solution is simply `window.myContainer` but you probably dont want to leak globals. Quote Link to comment Share on other sites More sharing options...
Bkf Posted January 19, 2016 Author Share Posted January 19, 2016 I'm going to have lots of movieclips so that approach does not seem proper, is there any other approach? Quote Link to comment Share on other sites More sharing options...
BobF Posted January 19, 2016 Share Posted January 19, 2016 More info may be helpful. For example, is each clip displayed by a separate container on the page with a separate button for each container? Or, is there one button and one container and you have some mechanism for switching clips within the container? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted January 19, 2016 Share Posted January 19, 2016 It doesnt matter how many movieclips you have. Keep them all in a map, an array or an object if it makes more sense. So long as you hold the reference you can access the movieclip instance, then it doesnt matter if you change structure or hierarchy. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.