Skip to main content
Known Participant
September 1, 2013
Question

how to use a scaled object(MC) to fill the background with the new properties

  • September 1, 2013
  • 2 replies
  • 618 views

So lets say i have a stage 300 to 200 and all object that i have are for this dimensions.Also have an pattern function that fills the background.

But the user is thinking of resizing the stage to lets say 1024 to 480 (he switched from a phone to a tablet).And now the scale of the objects in the tablet screen are more than 3times before(when seen on the Phone)

How do i save the current new size object and use it in the creation of the new background (the 1024x480).

currently i have this :

public static const GAME_ORG_WIDTH:uint = 300;

public static const GAME_ORG_HEIGHT:uint = 200;

public function MainClass_road() {

                              addEventListener(Event.ADDED, init);

                    }

                    public function init(e:Event):void{

                               stage.scaleMode = StageScaleMode.NO_SCALE;

                                 stage.align = StageAlign.TOP_LEFT;

                                 stage.addEventListener(Event.RESIZE, setUpScreen);

                    }

                    public function setUpScreen(ev:Event):void{

                              stage.removeEventListener(Event.RESIZE, setUpScreen);

                              if(stage.fullScreenHeight > stage.fullScreenWidth){  

                                        gameStageWidth = stage.fullScreenWidth;

                            gameStageHeight = stage.fullScreenHeight;

                              }else {

                                        gameStageWidth = stage.fullScreenHeight;       // 480

                                        gameStageHeight = stage.fullScreenWidth;                     //1024

                              }

                              rescaleRatio = gameStageWidth / GAME_ORG_WIDTH;  

                              //rescale every object, ie:

                            myC.scaleX = myC.scaleY =   rescaleRatio;

                   //start filling the Background with the pattern

                                   tileBgF();

                    }

and then I use the while loop for filling the screen/background

public function tileBgF(e:Event=null):void {

                                                  var bgClip = MyC;

                                                  var i:int = 0;

                                                  var j:int = 0;

                                                  while (bgClip.x < stage.stageWidth) {

                                                            bgClip = MyC;

                                                            while (bgClip.y < stage.stageHeight) {

                                                                      bgClip = MyC;

                                                                      tileLayer.addChild(bgClip);

                                                                      bgClip.x = bgClip.width * i;

                                                                      bgClip.y = bgClip.height * j;

                                                                      j++;

                                                            }

                                                            j = 0;

                                                            i++;

                                                  }

                                                  addChildAt(tileLayer,0);

                                        }

why does it give me

Line 521120: Access of undefined property MyC.
in public function tileBgF

and further more.After filling the background/screen with the pattern , how do i save it all like one big bitMap  so i can use /add it after time without doing all the checking of screen and things again.

This topic has been closed for replies.

2 replies

Inspiring
September 2, 2013

you have both written MyC and myC

in your code.

As3 is case-sensitive

Known Participant
September 1, 2013

and is it better to use

stage.fullScreenHeight

in the while loop or leave it like it is ,or its irrelevant

Known Participant
September 2, 2013

ofc ..... i did not see that. ok thanks.
but now how do i add a second Sprite of tileLayer with the same data but lets say to be 50px to the left