A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: AS3 onResize question...

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    AS3 onResize question...

    Hi,

    Just getting to grips with as3 and have hit a stumbling block!
    I have an fla that has four mc's - that together with this script create a carousel - with one mc acting as the hub and the other three rotating around it .
    PHP Code:
    import idv.cjcat.display.carousel.Carousel;
    import idv.cjcat.display.carousel.Pony;

    var 
    balls:Array = [ball1_mcball2_mcball3_mc];
    var 
    carousel:Carousel = new Carousel;
    //centers and radii for the (x, y) coordinate
    carousel.centerX stage.stageWidth/2;
    carousel.radiusX 150;
    carousel.centerY stage.stageHeight/2;
    carousel.radiusY = -50;

    //center and radius for the scaleX and scaleY property
    carousel.centerS 1;
    carousel.radiusS 0.5;

    carousel.axis axis_mc;

    for (var 
    i:int 0balls.lengthi++) {
        
    carousel.add(new Pony(balls[i], Math.PI /*this is the 'phase' of the Pony around the carousel*/));
    }

    addChild(carousel);
    addEventListener(Event.ENTER_FRAMErotate);
    function 
    rotate(e:Event):void {
        
    carousel.phase getTimer() / 500;
        
    carousel.render();
    }
    addEventListener(Event.ENTER_FRAMEtweak);
    function 
    tweak(e:Event):void {
        
    carousel.phase mouseX / -100;
        
    carousel.render();

    This all works great until I complicate matters by trying to integrate some liquid layout type stuff - by using this script:
    PHP Code:
    import flash.display.*;

    //set stage position
    stage.align StageAlign.TOP_LEFT;
    //do not let any of the stage scale
    stage.scaleMode StageScaleMode.NO_SCALE;

    //add stage resize listener, 
    //this is called when the browser or flash movie is resized
    this.stage.addEventListener(Event.RESIZEresizeHandler); 

    //create trigger that is fired when resize is triggered
    function resizeHandler(event:Event):void {     
    position();
    }

    //call resize function at start of movie
    //this way everything starts in the right place
    position();

    //this is the function contains all your code
    //you can add your own as long as there 
    //is a movie clip on the stage that you named correclty
    function position(){
    middleClip.stage.stageWidth/2;
    middleClip.stage.stageHeight/2;
    axis_mc.stage.stageWidth/2;
    axis_mc.stage.stageHeight/2;
    ball1_mc.stage.stageWidth/2;
    ball1_mc.stage.stageHeight/2;
    ball2_mc.stage.stageWidth/2;
    ball2_mc.stage.stageHeight/2;
    ball3_mc.stage.stageWidth/2;
    ball3_mc.stage.stageHeight/2;
    topClip.width stage.stageWidth;
    topClip.0;
    topClip.0;
    botClip.width stage.stageWidth;
    botClip.0;
    botClip.stage.stageHeight topClip.height;

    This works great and positions 'all' the elements on the stage as they should be. But, but, but when I resize the stage everything moves in relation apart from the three mc's that rotate (ball1_mc, ball2_mc, ball3_mc) which simply stay where are?

    What am I doing wrong or not doing at all that makes this happen? I have going at this most of the afternoon to no avail

    I have attached the folder as a .zip file if anyone needs it to see what I mean?

    Really grateful to anyone that can offer me some experience in the field of the workings of AS3

    Here's hoping!
    ***crosses fingers***
    Attached Files Attached Files

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    You need to update these vars within position();
    carousel.centerX
    carousel.radiusX
    carousel.centerY
    carousel.radiusY

  3. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...blimey! that was much easier than I was expecting!

    Thanks a bunch JAQUAN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center