1. #1
    Sencha User
    Join Date
    Jan 2013
    Posts
    2
    Vote Rating
    0
    talnicolas is on a distinguished road

      0  

    Default Unanswered: Access variable in my own Javascript file

    Unanswered: Access variable in my own Javascript file


    I have a Sencha Touch 2.1 / Cordova 2.0 application for Android that seems to not include my own Javascript files correctly. In my app.js I make a call like so:

    Code:
    CustomJS.exampleFunction();

    which is supposed to call the function in a CustomJS.js file that lools like so:


    Code:
    var CustomJS= { 
        exampleFunction: function(){
            return cordova.exec(function(data){}, function(data){}, "ExamplePlugin", "aFunction", []);     
        }
    };

    But when I launch my application on the device I get this error in the logcat:


    Code:
    ERROR/Web Console(9933): Uncaught TypeError: Object function () {
            ...    ...
    } has no method 'exampleFunction' at file:///android_asset/www/app.js 
    


    Here is the js part of the app.json I used to build my sencha app:


    Code:
    "js": [     
        {        
            "path": "cordova-2.0.0.js"    
        },      
        {        
             "path": "lib/CustomJS.js"    
        },    
        {        
            "path": "touch/sencha-touch.js"    
        },    
        {        
            "path": "app.js",       
            "bundle": true,  
            "update": "delta"    
        }
    ]

    I have looked everywhere I could to find something that would explain why I can't access my CustomJSvariable in my app.js but didn't find anything.

    Does anyone know if I'm doing anything wrong? Or is there a simpler/better way to achieve that?
    (The same configuration works on iOS)

  2. #2
    Sencha Premium Member
    Join Date
    Aug 2012
    Location
    San Juan, PR
    Posts
    27
    Answers
    1
    Vote Rating
    2
    yencarnacion is on a distinguished road

      0  

    Default


    In your index.html or app.html
    try:
    <script src="touch/sencha-touch-2.1.0/sencha-touch-all.js"></script>
    <link rel="stylesheet" href="touch/sencha-touch-2.1.0/resources/css/sencha-touch.css">
    <script src="lib/CustomJS.js"></script>
    <script type="text/javascript" src="app.js"></script>

    Yamir

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Posts
    2
    Vote Rating
    0
    talnicolas is on a distinguished road

      0  

    Default


    Thanks for your answer.

    It isn't working like that either, and anyway from what I read I don't think we're supposed to modify the index.html ourselves.

  4. #4
    Sencha User
    Join Date
    Dec 2011
    Location
    Sacramento, California
    Posts
    75
    Vote Rating
    8
    gypsie is on a distinguished road

      0  

    Default


    talnicolas,

    Have you found solution to this problem? I am still wrestling with integration of Sencha Touch 2.1.1 with cordova-2.2.0

    Error I am getting on startup on device is RefferenceError: Can't find variable: cordova.
    I am including Cordova js same as you do in app.json:

    Code:
    {
    "path": "cordova-2.2.0.js"
    }
    launch is never even called. it is stuck on loading screen.