mardi 11 avril 2017

How to get browser zoom factor to work?

I'm trying to determine if a user has zoomed in on their web page and it looks like there are a few properties that are available to help determine this one of them being the stage.browserZoomFactor. Nothing I've tried is changing the value. It is always 1.

Here is the code I'm using:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ift.tt/rYUnH9" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"

               minWidth="955" minHeight="600" 
               applicationComplete="application1_applicationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            protected function getZoomInfo():void {
                var clientWidth:int;
                var scaleFactor:Number

                if (ExternalInterface.available) {
                    ExternalInterface.marshallExceptions = true;
                    clientWidth = ExternalInterface.call(string, ExternalInterface.objectID);
                    scaleFactor = Number(Number(stage.stageWidth/clientWidth).toFixed(1));
                }

                zoomFactorLabel.text = "";
                zoomFactorLabel.text += "Client width: "+clientWidth + "\n";
                zoomFactorLabel.text += "Stage width: "+stage.stageWidth + "\n";
                zoomFactorLabel.text += "Calculated Scale factor: "+scaleFactor + "\n";
                zoomFactorLabel.text += "Browser Zoom factor: "+stage.browserZoomFactor + "\n";
                zoomFactorLabel.text += "Content Scale Factor: "+stage.contentsScaleFactor + "\n";
                zoomFactorLabel.text += "DPI: "+applicationDPI;
            }

            protected function application1_applicationCompleteHandler(event:FlexEvent):void {
                stage.addEventListener(Event.BROWSER_ZOOM_CHANGE, browserZoomChange);
                getZoomInfo();
            }

            protected function browserZoomChange(event:Event):void {
                trace("Zoom changed");
                zoomFactorLabel.text = "Zoom changed";
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <fx:String id="string"><![CDATA[
function(clientId) {
    var clientWidth = document.getElementById(clientId).clientWidth;
    return clientWidth;
}
        ]]></fx:String>
    </fx:Declarations>

    <s:TextArea id="zoomFactorLabel" horizontalCenter="0" verticalCenter="-60"/>
    <s:Button label="check browser zoom" click="getZoomInfo()" horizontalCenter="0" verticalCenter="30"/>

</s:Application>

I've also set the browserzoom to scale and noscale in the HTML wrapper page. And neither option seems to do anything. Browser zoom is supposed to be enabled by default.

If I manually get the swf object client width I can compare it to the stage width and get a scale factor but doesn't work in Firefox (on Mac) it does work on Safari (on Mac).

  • Adobe Blog post on browser zoom factor.
  • Release notes on Flash Player 21.

Aucun commentaire:

Enregistrer un commentaire