cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

When starting the Experience, methods are automatically called

JH_9310184
9-Granite

When starting the Experience, methods are automatically called

Hi Community!

I have several 3D toggle buttons in my experience, which call one method each when pressed and unpressed. At startup all buttons are unpressed. Here Studio runs directly through the respective methods, which should be run only when the button is really unpressed.

Is there a way to disable or prevent this?
Disabling the button does not really help. The method of the disabled button is still called.

The buttons change parameter values, such as the value of a manometer, depending on their status. However, the manometer value should be different at the start than when the button is not pressed.


I am curious about ideas and suggestions!

Best regards
Jonas

ACCEPTED SOLUTION

Accepted Solutions

Hi @JH_9310184 

I think, I was able to reproduce the issue with one 3D toggle button. So I defined callback function for pressed and unpressed event and set the 3D Toggle to unpress and then start in preview- The unpressed  event then fired.

To prevent this at load time - I simple defined a global variable which is initialized at runtime  when project  enter the view. The function will check the value and will change it and return so that the further action are omitted. Possibly this approach could be helpful for you:

//----------------------------------------------
//global variable which is set on enter in the view
$scope.firstTimePressUnpress_called=false
//----------------------------------------------
//callback for the 3d Toggle pressed event
$scope.pressedEvent=function()
{
  if(! $scope.firstTimePressUnpress_called) 
  {$scope.firstTimePressUnpress_called=true; return;}
console.warn("Pressed event");
//do further actions here...
}
//----------------------------------------------
//callback for the 3d Toggle Unpressed event
$scope.unpressedEvent=function()
{
if(! $scope.firstTimePressUnpress_called) 
  {$scope.firstTimePressUnpress_called=true; return;}
console.warn("UN PRESS event");
//do further actions here...
}

View solution in original post

4 REPLIES 4

Hi @JH_9310184 

I think, I was able to reproduce the issue with one 3D toggle button. So I defined callback function for pressed and unpressed event and set the 3D Toggle to unpress and then start in preview- The unpressed  event then fired.

To prevent this at load time - I simple defined a global variable which is initialized at runtime  when project  enter the view. The function will check the value and will change it and return so that the further action are omitted. Possibly this approach could be helpful for you:

//----------------------------------------------
//global variable which is set on enter in the view
$scope.firstTimePressUnpress_called=false
//----------------------------------------------
//callback for the 3d Toggle pressed event
$scope.pressedEvent=function()
{
  if(! $scope.firstTimePressUnpress_called) 
  {$scope.firstTimePressUnpress_called=true; return;}
console.warn("Pressed event");
//do further actions here...
}
//----------------------------------------------
//callback for the 3d Toggle Unpressed event
$scope.unpressedEvent=function()
{
if(! $scope.firstTimePressUnpress_called) 
  {$scope.firstTimePressUnpress_called=true; return;}
console.warn("UN PRESS event");
//do further actions here...
}

Hi Roland,
thanks for the tip! That works in any case. But I have to create a separate global variable for each button, because otherwise it will be overwritten directly in the first function.
I was hoping there is a more charming way here.

Nevertheless, it solves my concern. Thanks!

Regards
Jonas

Thanks for the feedback. Possibly you can use only one global variable for all pressed and unpressed functions which is set to false on load time and with some delay (locking time) it will be set back to true to allow the execution of the buttons functions. Something like this:

 

 

//----------------------------------------------
//global variable which is set on enter in the view to false 
//means it lock all methods to work
$scope.firstTimePressUnpress_called=false
//----------------------------------------------
//callback for the 3d Toggle pressed event
$scope.pressedEvent=function()
{
  if(! $scope.firstTimePressUnpress_called) 
  {//$scope.firstTimePressUnpress_called=true; 
    return;}
console.warn("Pressed event");
//do further actions here...
}
//----------------------------------------------
//callback for the 3d Toggle Unpressed event
$scope.unpressedEvent=function()
{
if(! $scope.firstTimePressUnpress_called) 
  {//$scope.firstTimePressUnpress_called=true; 
    return;}
console.warn("UN PRESS event");
//do further actions here...
}

//
$scope.$on('$ionicView.afterEnter', function() {
  //this event is called when view is entered
  $timeout( ()=> {$scope.firstTimePressUnpress_called=true;},2500);})
//calls with delay of 2.5 seconds to unlock the functionality

 

 

Ah! Great idea, thank you!

Announcements

Top Tags