imperative vs declarative error

Last post 09-07-2006 11:18 AM by maximilyan. 2 replies.

Sort Posts:

  • imperative vs declarative error

    09-07-2006, 4:57 AM
    • Member
      20 point Member
    • maximilyan
    • Member since 04-07-2006, 6:12 AM
    • Posts 4

    hi,

    I keep getting an error accessing a custom object that was initialized using the pageLoad event,
    While initializing the same object from xml scripting language works fine.

    What am I doing worng?


    ---------------------------------------------------------------------------------------------------------------------------------------------

    Type.registerNamespace('test');
    test.TestObject =
    function(associatedElement) {
       test.TestObject.initializeBase(
    this, [associatedElement]);

       var _testProperty;

       this.initialize = function() {
          test.TestObject.callBaseMethod(
    this, 'initialize');
       }

       this.dispose = function() {
          test.TestObject.callBaseMethod(
    this, 'dispose');
       }

       this.getDescriptor = function() {
         
    var td = test.TestObject.callBaseMethod(this, 'getDescriptor');
          td.addProperty(
    'testProperty', Number);
         
    return td;
       }

       this.get_testProperty = function() {
         
    return _testProperty;
       }
       this.set_testProperty = function(value) {
          _testProperty = value;
       }

    }
    test.TestObject.registerSealedClass('test.TestObject', Sys.UI.Control);
    Sys.TypeDescriptor.addType(
    'script', 'testObject', test.TestObject);

     -------------------- this is working fine ----------------------------------

    <html>
    ....

    <div id="myDiv">123</div>
    <input id="Button1" onclick="javascript:showValue();" type="button" value="button" />

    <script type="text/javascript">
       function showValue() {
         
    var obj = $object('myDiv');
          alert(obj.get_testProperty());
    }
    </script>

    <script type="text/xml-script">
       <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
          <components> 
             <testObject id=
    "myDiv" testProperty="10" />
          </components>
       </page>
    </script>

    </html>

     -------------------- this code return Error ----------------------------------
    <html>
    ......

    <div id="myDiv">123</div>
    <input id="Button1" onclick="javascript:showValue();" type="button" value="button" />

    <script type="text/javascript">
       function pageLoad() {
         
    var obj = new test.TestObject($('myDiv'));
          obj.set_testProperty(10);
       }

       function showValue() {
         
    var obj = $object('myDiv');
          alert(obj.get_testProperty());
       }
    </script>

    </html>

    Thanks
     

     

  • Re: imperative vs declarative error

    09-07-2006, 10:40 AM
    • Member
      10 point Member
    • oribolzi
    • Member since 03-22-2006, 7:35 AM
    • Posts 3

       function pageLoad() {
         
    var obj = new test.TestObject($('myDiv'));

          obj.initialize();
          obj.set_testProperty(10);
       }

  • Re: imperative vs declarative error

    09-07-2006, 11:18 AM
    • Member
      20 point Member
    • maximilyan
    • Member since 04-07-2006, 6:12 AM
    • Posts 4

    I just forgot to put this line in the posted code….
    By the way the properties must be set before the initialization stage.

    Still by initializing the object programmatically you’ll get an error! You can try it…

Page 1 of 1 (3 items)