1. #1
    Sencha Premium Member hagai's Avatar
    Join Date
    Jan 2013
    Posts
    17
    Vote Rating
    0
    hagai is on a distinguished road

      0  

    Default Unanswered: Problem with Global var in Sencha Touch

    Unanswered: Problem with Global var in Sencha Touch


    Hello, we have a problem with "dynamic screen resolution" in Sencha Touch.
    We want to calculate it using "Scale Factor" something like:
    //Original Game Size
    GameWidth = 960;
    GameHeight = 640;
    //Calc Scale Factor
    scaleFactor = Math.min(Ext.getBody().getSize().width / GameWidth, Ext.getBody().getSize().height / GameHeight);

    and after that we want to use the Scale Factor variable in every component, image etc..

    But there's a problem !!

    Since it's load all the files asynchronously by design, we can't make sure the calculation will be loaded first and only after that all the view will use the scale factor,
    all the views are in app.js and the scale factor calculation done in lunch function of the main controller.

    Alternatively, when we try to load a view from the code, something like:
    Ext.Viewport.add({ xclass: 'testApp.view.first', id: 'first' });
    Ext.getCmp('first').show();
    and not from the app.js we got this warning:
    [WARN][Anonymous] [Ext.Loader] Synchronously loading 'testApp.view.first'; consider adding 'testApp.view.first' explicitly as a require of the corresponding class

    Which I guess is not the right way to do it.

    So what is the best way to load it synchronically and to use some sort of pre calculated (or pre-defined) global variable in all the app views?

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    482
    Answers
    24
    Vote Rating
    48
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      1  

    Default


    So I think what you need to know about and use is the require property you need to use on every class. If your app is creating a view of type App.view.Main, then it requires that view, and you need to tell the framework that by adding requires: ['App.view.Main'] to the application.

    Sencha Touch will dynamically load classes in during development that you didn't explicitly require - this is the warning you're seeing. But you must require the classes because when you build to production or testing, all the classes are put into one single javascript file based upon your classes' requirements. Then you don't have dynamic loading to fall back on.

    I would have a util class to calculate your scaleFactor. I would then add it as a required class of the app. Just put a factor property in the config, set the class as a singleton and initConfig on the class' constructor (similar example, without wishing to self-promote, here: http://senchatouchdev.com/wordpress/...cha-touch-2-x/)

    You need to do the same for your view. From your view you could then do something like width: App.util.Scale.getFactor() - strictly speaking, as the view has used the util class, it too, must require it.

    I would imagine you would then, on the application's launch, make a call to:
    App.util.Scale.calculateFactor() - which would do your calculations and call the setFactor() method on the class that Sencha Touch has created for you.
    I blog about Sencha Touch at www.senchatouchdev.com

  3. #3
    Sencha Premium Member hagai's Avatar
    Join Date
    Jan 2013
    Posts
    17
    Vote Rating
    0
    hagai is on a distinguished road

      0  

    Default


    Thanks!! it's working good now. :-)

    BTW, maybe you have an idea if we can also use this util var inside saas somehow?

  4. #4
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    482
    Answers
    24
    Vote Rating
    48
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      1  

    Default


    You can always use the style config on the components in sencha touch if you need to.
    I blog about Sencha Touch at www.senchatouchdev.com

  5. #5
    Sencha Premium Member hagai's Avatar
    Join Date
    Jan 2013
    Posts
    17
    Vote Rating
    0
    hagai is on a distinguished road

      0  

    Default


    Yeah that's what we did for now, the H and W inside the config and all the other inside the CSS, just wanted to know if there's more elegant way to do it and not by separating it to 2 parts.
    Hagai Pipko

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar