Problem to set some properties for labels created dynamically (overflow and horizontalAlign)

Hi everybody,
I have a problem with labels being dynamically created :
var newNode=new cc.Node('myNode');
var newLabel=newNode.addComponent(cc.Label);

this works fine, but I cant succeed to adjust the following label properties :
newLabel.overFlow and newLabel.horizontalAlign
I tried
newLabel.overFlow='RESIZE_HEIGHT' ;
or
newLabel.overFlow= ('RESIZE_HEIGHT',500); and other things, nothing works…
same problem with
newLabel.horizontalAlign= ('LEFT',20) ;

I probably miss something, but I am unable tu find what… any help?
my cocos creator version is 1.5

Hi,
Use cc.Label.Overflow enum like this:

Here is document:
http://cocos2d-x.org/docs/api-ref/creator/v1.5/classes/Label.html#property_overflow
http://cocos2d-x.org/docs/api-ref/creator/v1.5/enums/Label.Overflow.html

Thank you for the answer, but I already tryed this solution, it doesn’t work with me, here is the script :

Peuple:function(){
  var content = cc.find("Go"); // Go = cc.Canvas
  var b=250; // y initial  position
    for(i=1;i<gorge.length;i++) { // array containing sentences
        var newNode=new cc.Node;
        newNode.parent=content;
        var newLabel = newNode.addComponent(cc.Label);
        newNode.y= b; 
        newLabel.string=gorge[i];
        newLabel.overflow=cc.Label.Overflow.RESIZE_HEIGHT;
        newLabel.horizontalAlign=cc.Label.HorizontalAlign.LEFT;
        b-=40;
    }

Here is the result of the script above :

the result of this script

Could be an issue with

newNode.parent = content;

use

content.addChild(newNode);

instead?

You probably need to specify the newNode width and height as well

newNode.width = x;
newNode.height= y;

Thank you for your answer, but your solution doesn’t work either… What I would like to know is if you (sgmaknae), nshmura, or someone else have ever use (successfully) those 2 properties (overflow and horizontalAlign)…

I copied your code and added the recommended steps to get it working on my environment.
(not sure about horizontal alignment but the overflow seems to be working)

Thanks for your answer. It’s very strange, have you tried with long sentences like mines (or with a short-width layout as container for example) ? Can you show me the result with a screen please (because you should see if it’s centered or left aligned)…

Codes

var content = cc.find("Canvas"); // Go = cc.Canvas
var b=250; // y initial  position
var newNode=new cc.Node;
var newLabel = newNode.addComponent(cc.Label);
newLabel.string="TstgrtSY SERYNGsdfg RTYSBDGDFGSDGBSR sERTVSRDTGdfgs ERSTSDVG ERSDVFGDFG";
 newLabel.overflow=cc.Label.Overflow.RESIZE_HEIGHT;
newLabel.horizontalAlign=cc.Label.HorizontalAlign.LEFT;
b-=40;
newNode.width = 400;

1 Like

Ok. Thank you very much Sgmaknae. I didn’t see the interest to specify the node’s width (as you indicated me, but I forgot this point) to set the HorizontalAlign property, but that is the point… To access horizontalAlign (and overflow) properties of a node, one must set node’s width…