Domanda

I need to add the width property to the canvas .By traceing the value iam geting its value as zero though it contain images and has a width.

//code of adding 5 canvases to the main canvas public function addcanvas(canarr:Array):void {

        var can_arr:Array=new Array();
        can_arr=canarr;
        for(var c:int=0;c<can_arr.length;c++)
        {

            canvasA=new Canvas();
            canvasA.id="canvasA";
            trace("ccc:"+c);
            canvasA.x=(c*10)+10;
            canvasA.y=0;2
            this.addChild(canvasA);

        }
                   trace("canvasA.width:  "+canvasA.width);
          }

and next i will add images into each canvas

//enter code here public function ClubCards(imgarr:Array):void
{ var Gimg_arr:Array = new Array(); Gimg_arr =imgarr;

            for(var j:int=0;j < Gimg_arr.length;j++)
            {
                myimage1 = new Image();
                myimage1.x=0+(j*20);
                myimage1.y=40;
                           myimage1.source=gameModule.getStyle(Gimg_arr[j].toString());

                GroupingImageListeners(myimage1);

                canvasA.addChild(myimage1);

            trace("canvasA.width:  "+canvasA.width );
        }

iam unable to know the width of the canvas which has images in it . can u please help me out.how can i get that canvas width Thank you in advance

È stato utile?

Soluzione

I can't add a comment, so I will add an answer saying this code should be triggered by a call to the updateDisplayList method (during the appropriate phase of the flex component life-cycle). I would suggest reading and understanding this update cycle before doing any further Flex development (it will save you a lot of time in the long-run).

More info can be found here: http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_2.html

UPDATE

Since you mentioned Canvas, I updated the link to point to the 3.x version of the article

Altri suggerimenti

You did not make your canvas invalidate its size. Without an order to redraw, I don't think you'll get the correct size. Without Event.RENDER dispatched your component will not calculate its size.

Maybe you should try:

canvas.invalidateSize();

before accessing its width and see the result. This should make your canvas call its method measure() and calculate its size.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top