Announcement

Collapse
No announcement yet.

Button won't execute function from within an efsLib file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Button won't execute function from within an efsLib file

    How do I get a button defined in an *.efsLib library file to execute a function.

    I can call the function directly so as far as I know it is defined but when called by:

    "drawTextAbsolute(0, 11, " Toggle Band @URL=EFS:changeColor", Color.white, null, xFlags , "Courier New", 11, -55); "

    and the button on the chart is clicked it returns:

    "...line 0: Failed to call 'changeColor': function is not defined."

    Here is a sample efs file: del b.efs
    PHP Code:
    debugClear();
    var 
    myLibrary addLibrary ("del_ButtonTest.efsLib"); 
    function 
    main(){
        
    myLibrary.callDraw();

    And the corresponding *.efsLib file: del_ButtonTest.efsLib
    PHP Code:
    var bButtonPressed       false;
    var 
    bDrawBand            false;
    function 
    callDraw(){
        var 
    xFlags Text.ONTOP Text.BUTTON Text.RELATIVETOLEFT Text.RELATIVETOBOTTOM;
        if ( 
    isLastBarOnChart() && bDrawBand == true ) {
            
    addBand0PS_SOLID5Color.black, -66 );
        }
        
    drawTextAbsolute(011" Toggle Band @URL=EFS:changeColor",  Color.whitenullxFlags "Courier New"11, -55);     
    }
    //== function determines if a button was pressed
    function getButtonPressed(nButtonPressed) {
        if(
    nButtonPressed == BUTTON_LEFT) {
            return(
    1);
        }
        else {
            return(
    0);
        }
    }
    //== performs a specific task if our button was pressed
    function changeColornButtonPressed ) {//code inside here executed immediately while in main it waits for a new tick  
        
    if ( getButtonPressednButtonPressed ) == ) {
            
    bButtonPressed true;
            
    bDrawBand = !bDrawBand;
            
    clearBands();
            
    main();
        }
        return;

    I would really appreciate some help.


    Wayne
    Last edited by waynecd; 07-26-2014, 04:50 AM.

  • #2
    It seems that:
    " Toggle Band @URL=EFS:changeColor"
    in drawTextAbsolute() only points/refers to the eSignal global object.

    Its there a way to have it point to the efsLib instead. The use of the "this" word doesn't seem to work (including assigning "this" to a private variable within efsLib), at least as I have applied it.

    I can of course declare "var bDrawBand", "function changeColor", & "function getButtonPressed" in the calling efs but that defeats the purpose of using the *.efsLib.

    Wayne
    Last edited by waynecd; 07-27-2014, 01:29 AM.

    Comment


    • #3
      Wayne,

      EASY fix for all of this.

      Remember, in Javascript, an assignment made to a non-var declared variable is always placed in the global namespace.

      So, at the top of your efslib, just do this:

      _changeColor = changeColor;

      Then, modify:

      " Toggle Band @URL=EFS:changeColor"

      To:

      " Toggle Band @URL=EFS:_changeColor"

      Voila!

      (tongue in cheek) : Dude, I hope you're just monkeying around and not seriously trying to call main() from a callback inside of an efsLib!

      Wayne, I'm leaving the eSignal "Circle of Friends" for good at the beginning of October when my annual subscription is up. It's been 11 years with them and the times, well, they are a changin'. If you have any questions, just send me PM's and I'll be glad to help, even past October if you like.
      Last edited by SteveH; 07-27-2014, 10:13 AM.

      Comment


      • #4
        Steve,

        Thanks for the flawless solution and offer of assistance.

        lol: "main()" was an oversight I didn't delete when cleaning up the sample code for posting.

        You are also right about the changing times.

        Wayne

        Comment

        Working...
        X