# onPress calling a function - scope issue?

**URL:** https://forum.kirupa.com/t/onpress-calling-a-function-scope-issue/272837
**Category:** flash
**Created:** [October 8, 2008, 7:52pm UTC](https://forum.kirupa.com/t/onpress-calling-a-function-scope-issue/272837 "2008-10-08T19:52:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![krisjl20](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@krisjl20](https://forum.kirupa.com/u/krisjl20)
#### Post date: [October 8, 2008, 7:52pm UTC](https://forum.kirupa.com/t/onpress-calling-a-function-scope-issue/272837/1 "2008-10-08T19:52:31Z")

</div>

I think this is a scope issue, but can’t be sure. I am using FlashDevelop, Actionscript 2.0 to create my movie. I call the sendAndLoad() function to display data from a database. I also have “Previous” and “Next” buttons to move through different data.

Since I was going to load data in three different locations (Load, Previous, Next) I created a LoadData() function. This function contains the sendAndLoad() to the server.

The initial load works great with the LoadData() function, the first record is displayed correctly. My problem is when I program the onPress for the Previous and Next buttons.

Why does my LoadData() function not run when inside the Previous/Next button onPress events?

Thanks,  
Kris

example code:

class Main  
{  
private var parent:MovieClip;

```
public function LoadData()
{			
	var sVars2:LoadVars = new LoadVars();
	sVars2.cID = _global.ClientID;
	sVars2.tID = _global.cTicketID;
	
	var lVars2:LoadVars = new LoadVars();
	lVars2.onLoad = function(success) {
		if (success) {
			//success
		} else {
			//not successful
		}
	} 
	sVars2.sendAndLoad(url, lVars2, "POST");
}

function Main(mc:MovieClip)
{
	this.parent = mc;	

            //Buttons Created	
	
	_root["next"].onPress = function() {	
		this.LoadData();
	}	
	_root["prev"].onPress = function() {
		this.LoadData();
	}
	LoadData();
}

static function main(mc:MovieClip)
{
      var app = new Main(mc);		
}		

```

}
