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

setStyle not affecting components already formatted

Guest
Nov 14, 2009 Nov 14, 2009

I have a form and everything is components:  labels, comboBox button.  I have applied a text format to all the elements.  I want the user to select a font from the combo box drop down and then all fonts change.  However, I can only get this to work when I don't apply any textFormats to my components initially.    I know in as2 you had to setNewTextFormat, is it somewhat similar with this setStyle?  Here is my code:

package {      import flash.display.*;      import flash.events.*;      import flash.text.*;      import fl.controls.*;      import fl.managers.StyleManager;      import fl.motion.Color;      import flash.geom.ColorTransform;      public class CatProcess extends MovieClip      {           //LABEL VARIABLES           var headingTxt:Label;           var userLabel:Label;           var paletteLabel:Label;           var ageLabel:Label;                      //TEXT INPUT VARIABLES           var ageInputBox:TextInput;           var nameInputBox:TextInput;                      //TEXT FORMAT VARIABLES           var standardFormat:TextFormat;           var headingFormat:TextFormat;           var arialFormat:TextFormat           var courierFormat:TextFormat;                 //MISC VARIABLES           var userName:String;           var fontCombo:ComboBox;           var submit_btn:Button;                          public function CatProcess()           {                               //TEXT FORMATS                headingFormat=new TextFormat();                headingFormat.font = "Arial";                headingFormat.size=16;                                standardFormat=new TextFormat()                standardFormat.font="Arial"                standardFormat.size=12;                                arialFormat=new TextFormat();                arialFormat.font = "Arial";                arialFormat.size=12;                                courierFormat=new TextFormat();                courierFormat.font="courier"                courierFormat.size=12;                //FORM COMPONENT ELEMENTS                //Heading                headingTxt=new Label();                headingTxt.text = "Olivers Cat Sanctuary";                headingTxt.autoSize = TextFieldAutoSize.LEFT;                headingTxt.setStyle("textFormat",headingFormat);                headingTxt.move(183.2,22);                addChild(headingTxt);                //Name Label                userLabel=new Label();                userLabel.text = "Please Enter your name";                userLabel.autoSize = TextFieldAutoSize.LEFT;                userLabel.setStyle("textFormat",standardFormat);                userLabel.move(50,106);                addChild(userLabel);                //Name inputBox                nameInputBox=new TextInput ();                nameInputBox.move(400,103);                addChild(nameInputBox);                //Palette Label                paletteLabel=new Label();                paletteLabel.text = "Please select a font";                paletteLabel.autoSize = TextFieldAutoSize.LEFT;                paletteLabel.setStyle("textFormat",standardFormat);                paletteLabel.move(50,157);                addChild(paletteLabel);                //Palette ComboBox                fontCombo=new ComboBox();                fontCombo.addItem({label:"Arial"});                fontCombo.addItem({label:"Courier"});                fontCombo.move(400,157);                addChild(fontCombo);                fontCombo.addEventListener(Event.CHANGE, comboHandler);                ageLabel=new Label();                ageLabel.text = "Please enter your age";                ageLabel.autoSize = TextFieldAutoSize.LEFT;                ageLabel.setStyle("textFormat",standardFormat);                ageLabel.move(50,209);                addChild(ageLabel);                ageInputBox = new TextInput();                ageInputBox.move(400,211);                addChild(ageInputBox);                submit_btn=new Button();                submit_btn.move(255,258);                submit_btn.label = "submit";                submit_btn.setStyle("textFormat",standardFormat);                addChild(submit_btn);           }//end constructor function           private function comboHandler(event:Event):void           {                var fontType:String = event.currentTarget.selectedItem.label;                if (fontType== "Arial") {                     StyleManager.setStyle("textFormat", arialFormat);                }                if (fontType=="Courier") {                     StyleManager.setStyle("textFormat", courierFormat);                }                           }                 } }

TOPICS
ActionScript
1.4K
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
Guest
Nov 15, 2009 Nov 15, 2009

Does no-one know the answer or is there a reason why no-one's answering, ie have I put too much code in?

really need help with 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
Participant ,
Nov 15, 2009 Nov 15, 2009

Nicolanicola,

     I brought all your code into an AS3 script. Ran the course and it switched from Arial to Courier with no problem. I checged some of the point size and it worked ok.

Socalfish

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
Guest
Nov 16, 2009 Nov 16, 2009

Were all the components changed?  I can get the comboBox to change font and the text on the submit button, that's all.

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
Participant ,
Nov 16, 2009 Nov 16, 2009

All the components you use in your app need to be in the library. I built a blank fla and added to the stage the componts needed then deleted them. But you would get errors if you did not have them already added in your fla file. The coding you had only changed the Name and Age when I choose another font. I changed a couple of settings in the .as file like the title and that worked ok as well.

I attached the fla and your .as file. Save them to a seperate folder and run the fla file. Are you using CS4? That is what the fla was built in.

Message was edited by: socalfish It appears I can not upload the fla or the .as file. Sorry.

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
Guest
Nov 16, 2009 Nov 16, 2009

Thanks for your help I really appreciate it.

Yes I'm working in CS4.  I added everything to the library, all the components.  It doesn't throw any error either.

What do you mean you changed the title?

I don't under stand because surely :

StyleManager.setStyle("textFormat", timesFormat);

should change all the component elements?  Mine is only changing the combobox and the submit button.  However if I don't add a textformat to the labels initially, the textformat applied by the listener function works.  But it works for the button and the comboBox regardless of whether I initially applied at textformat.

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
Participant ,
Nov 16, 2009 Nov 16, 2009

I changed the Title font size to see if it was being set.

In your event function try this for changing the other objects on your screen. Setting the StyleManager only changed the Text Input fields.

headingTxt.setStyle("textFormat", arialFormat);
userLabel.setStyle("textFormat", arialFormat);
paletteLabel.setStyle("textFormat", arialFormat);
ageLabel.setStyle("textFormat", arialFormat);
submit_btn.setStyle("textFormat", arialFormat);

Apply the same in your Courier statement.

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
Guest
Nov 16, 2009 Nov 16, 2009

But setting the style on manager is supposed to apply that style to all the components isn't it?

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
Engaged ,
Nov 16, 2009 Nov 16, 2009

package

{

     import flash.display.*;

     import flash.events.*;

     import flash.text.*;

     import fl.controls.*;

     import fl.managers.StyleManager;

     import fl.motion.Color;

     import flash.geom.ColorTransform;

public class CatProcess extends MovieClip

{

//LABEL VARIABLES

public var headingTxt:Label;

public var userLabel:Label;

public var paletteLabel:Label;

public var ageLabel:Label;

//TEXT INPUT VARIABLES

public var ageInputBox:TextInput;

public var nameInputBox:TextInput;

//TEXT FORMAT VARIABLES

public var standardFormat:TextFormat;

public var headingFormat:TextFormat;

public var arialFormat:TextFormat

public var courierFormat:TextFormat;

//MISC VARIABLES

public var userName:String;

public var fontCombo:ComboBox;

public var submit_btn:Button;

public function Main()

          {               

              //TEXT FORMATS

              arialFormat=new TextFormat();

              arialFormat.font = "Arial";

              arialFormat.size=12;

              courierFormat=new TextFormat();

              courierFormat.font="courier"

              courierFormat.size=12;

              //FORM COMPONENT ELEMENTS

              //Heading

              headingTxt=new Label();

              headingTxt.text = "Olivers Cat Sanctuary";

              headingTxt.autoSize = TextFieldAutoSize.LEFT;

              headingTxt.setStyle("textFormat",headingFormat);

              headingTxt.move(183.2,22);

              addChild(headingTxt);

              //Name Label

              userLabel=new Label();

              userLabel.text = "Please Enter your name";

              userLabel.autoSize = TextFieldAutoSize.LEFT;

              userLabel.setStyle("textFormat",standardFormat);

              userLabel.move(50,106);

              addChild(userLabel);

              //Name inputBox

              nameInputBox=new TextInput ();

              nameInputBox.move(400,103);

              addChild(nameInputBox);

              //Palette Label

              paletteLabel=new Label();

              paletteLabel.text = "Please select a font";

              paletteLabel.autoSize = TextFieldAutoSize.LEFT;

              paletteLabel.setStyle("textFormat",standardFormat);

              paletteLabel.move(50,157);

              addChild(paletteLabel);

              //Palette ComboBox

              fontCombo=new ComboBox();

              fontCombo.addItem({label:"Arial"});

              fontCombo.addItem({label:"Courier"});

              fontCombo.move(400,157);

              addChild(fontCombo);

              fontCombo.addEventListener(Event.CHANGE, comboHandler);

              ageLabel=new Label();

              ageLabel.text = "Please enter your age";

              ageLabel.autoSize = TextFieldAutoSize.LEFT;

              ageLabel.setStyle("textFormat",standardFormat);

              ageLabel.move(50,209);

              addChild(ageLabel);

              ageInputBox = new TextInput();

              ageInputBox.move(400,211);

              addChild(ageInputBox);

              submit_btn=new Button();

              submit_btn.move(255,258);

              submit_btn.label = "submit";

              submit_btn.setStyle("textFormat",standardFormat);

              addChild(submit_btn);

          }//end constructor function

private function comboHandler(event:Event):void

{

var fontType:String = event.currentTarget.selectedItem.label;

if (fontType== "Arial") {

StyleManager.setStyle("textFormat", arialFormat);

}

if (fontType=="Courier") {

StyleManager.setStyle("textFormat", courierFormat);

}

}

     }

}

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
Engaged ,
Nov 16, 2009 Nov 16, 2009

that works for me...

HTH!

-Ted

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
Guest
Nov 17, 2009 Nov 17, 2009

Is that my exact code you used?

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
Guest
Nov 19, 2009 Nov 19, 2009

Turns out this is a bug with Flash.  I have logged it with Adobe.

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
Guest
Nov 19, 2009 Nov 19, 2009

It's a bug!

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
Participant ,
Nov 19, 2009 Nov 19, 2009
LATEST

Good to know. Thanks for the info!

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