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

TextFormat parameters not applying until 2nd call

Contributor ,
Apr 17, 2023 Apr 17, 2023

I'm finding a sample label I add doesn't apply the assigned text formatting until the 2nd time it's called. The variables in this function aren't used anywhere else. I'm working on drawing a pie chart upon arrival at frame2. Before I get to the actual pie logic, I'm just testing the basic drawing parameters. The variables it uses are defined at the top of the AS3 for frame2:

 

var pieChart:Shape = new Shape;
var pieLabel_1:TextField = new TextField()
var tf:TextFormat = new TextFormat();

 

Then used in this stub function:

 

function draw_pie():void{
// Pie chart elements

trace("draw pie chart");
// Pie graphic logic TBD, place holder graphic
pieChart.graphics.beginFill(0xFFaaFF); // fill color
pieChart.alpha=.7; // temp alpha to see position relative to other graphics
pieChart.graphics.drawCircle(1660,545, 140); // (x upper left, y upper left, radius)
pieChart.graphics.endFill(); // end the fill

addChild(pieChart); // adds the circle to the stage


// label parameters

tf.font = "Arial";
tf.size = 56;
tf.color = 0x00FF00;
pieLabel_1.setTextFormat(tf);
pieLabel_1.text = "Label 1";
pieLabel_1.x = 1660;
pieLabel_1.y = 545;
addChild(pieLabel_1);
}

 

But the test label is intially drawn with the default format until an interaction on that same frame causes it to update, (at this point, just redraw). Is a flush or other refresh function needed before the setTextFormat function takes effect? The text format assignments in other components take effect without a refresh. Is an added action needed before a child can be added to the stage with the assigned format?

620
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

correct answers 1 Correct answer

Community Expert , Apr 18, 2023 Apr 18, 2023

defaultTextFormat is a property. So you should use it like this:

pieLabel_1.defaultTextFormat = tf;

 

Translate
Community Expert ,
Apr 17, 2023 Apr 17, 2023

Hi.

 

Use the defaultTextFormat property instead.

 

Regards,

JC

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
Contributor ,
Apr 18, 2023 Apr 18, 2023

For a text object created with:

var myText:TextField = new TextField()

and a format created with:

var tf:TextFormat = new TextFormat();

While myText.setTextFormat(tf); compiles, when I try myText.defaultTextFormat(tf); I get the error:

Attempted access of inaccessible method defaultTextFormat through a reference with static type flash.text:TextField.

Is there some other way to assign this?

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 ,
Apr 18, 2023 Apr 18, 2023

defaultTextFormat is a property. So you should use it like this:

pieLabel_1.defaultTextFormat = tf;

 

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
Contributor ,
Apr 18, 2023 Apr 18, 2023

That did it. Thank you. I wonder if there's a way to find when a parameter is a method or a property. And then, a list of all of the methods for all AS3 objects. The reference guide doesn't seem searchable based on that criteria. Is there a better one than https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/all-index-Symbols.html?

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 ,
Apr 18, 2023 Apr 18, 2023
LATEST

the as3 list properties, methods and events with each of those 3 categories separated.

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