A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: dynamic borders in AS3

  1. #1
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144

    dynamic borders in AS3

    Hey guys, finally learning AS3 and migrating some of my code snippets over from AS2. I tried reproducing one of my most used bit of code - the dynamic border - in AS3, but I have run into a small problem.

    PHP Code:
    var sw:int stage.stageWidth -1;
    var 
    sh:int stage.stageHeight -1;

    var 
    mc:MovieClip = new MovieClip();
    // change your color here
    mc.graphics.lineStyle(1,000000);
    mc.graphics.lineTo(sw,0);
    mc.graphics.lineTo(sw,sh);
    mc.graphics.lineTo(0,sh);
    mc.graphics.lineTo(0,0);
    addChild(mc); 
    So this code works great in Firefox but fails miserably in IE6, Flash Player 9. So my question is does anybody have a workaround that works on IE6, Player 9? Huge thanks for taking the time to read.

    *Also I'm sure someone will ask why does the border need to be added in AS - we get a lot of swfs from clients. We can insert code into swfs to fix little problems like this.

    thanks again!

  2. #2
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    Hey guys just an update on this issue. My "sw" and "sh" variables were coming back at with a value of -1. Someone on another board suggested the problem may be a delay on the stage initializing in IE. AKA 0 -1 = -1.

    This sounded good and I tried to do a check to see if the stage had initialized before assigning the values to both variables - like so -

    PHP Code:
    ////// Stage delays to initialize in IE browsers in as3?

    if (stage) {
        
    init();
    } else {
        
    addEventListener(Event.ADDED_TO_STAGEinit);

    }
    function 
    init(e:Event null):void {
        var 
    sw:int stage.stageWidth -1;
        var 
    sh:int stage.stageHeight -1;
        
        var 
    mc:MovieClip = new MovieClip();
        
    printbox.text sh.toString();
        
    removeEventListener(Event.ADDED_TO_STAGEinit);
        
    // entry point
        
    mc.graphics.lineStyle(1,0x999999);
        
    mc.graphics.lineTo(sw,0);
        
    mc.graphics.lineTo(sw,sh);
        
    mc.graphics.lineTo(0,sh);
        
    mc.graphics.lineTo(0,0);
        
    addChild(mc);

        
    trace(sh);

    It still doesn't work in IE 6 flash player 9 however. Anybody have any ideas?

  3. #3
    Senior Member
    Join Date
    Jul 2001
    Location
    San Jose California
    Posts
    144
    Another update -- problem solved. Used a set a timer to force a different execution order.

    PHP Code:
    var bugFix = function(){
        var 
    sw:int stage.stageWidth -1;
        var 
    sh:int stage.stageHeight -1;

        var 
    mc:MovieClip = new MovieClip();
    // change your color here
        
    mc.graphics.lineStyle(1,0xFF0000);
        
    mc.graphics.lineTo(sw,0);
        
    mc.graphics.lineTo(sw,sh);
        
    mc.graphics.lineTo(0,sh);
        
    mc.graphics.lineTo(0,0);
        
    addChild(mc);
    };

    setTimeout(bugFix,1); 
    randomly stumbled into this fix because of jBard's issue http://board.flashkit.com/board/show...96#post4214796

    nice when things work out unexpectedly :-)

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