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

Dynamically format dynamic font on a clicked movieClip

Explorer ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Hello!
I'm trying to have the ability to make a font smaller if a variable string is longer than the textfield (function updateFormat). I've been able to do it easily in the past, but this time there is an issue. Problem is that it is on a movie clip that is clicked on by the user (and there are multiple instances of said mc on the stage). So I want to have the function execute on the textfield within the clicked instance of the movieclip when it is clicked. I thought just having the code use currentTarget would be fine; however I get syntax error 1084 as Animate expects the right parenthesis before the dot. Any thoughts on how I can make this work? Pertinent code is provided below.

 

Thanks!

function movePrize(event: MouseEvent) {
	if (event.currentTarget.pz_txt.text == "") {
		event.currentTarget.pz_txt.text = wonPrize;
		updateFormat(event.currentTarget.pz_txt);
		wonPrize = null;
	} else {
		wonPrize = event.currentTarget.pz_txt.text;
		event.currentTarget.pz_txt.text = "";
	}
}

function updateFormat(event.currentTarget.pz_txt) {
var format:TextFormat = new TextFormat();
if (event.currentTarget.pz_txt.length > 20) {
                format.size=12;
} else if (event.currentTarget.pz_txt.length > 10 && event.currentTarget.pz_txt.length < 20) {
                format.size=14;
} else {
                format.size=16;
}

event.currentTarget.pz_txt.setTextFormat(format);
}

 

TOPICS
ActionScript , Code , Error , How to

Views

59

Translate

Translate

Report

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
no replies

Have something to add?

Join the conversation