# Reaching from a class

**URL:** <https://forum.kirupa.com/t/reaching-from-a-class/258270>\
**Category:** Uncategorized\
**Created:** [April 22, 2008, 4:33pm UTC](https://forum.kirupa.com/t/reaching-from-a-class/258270 "2008-04-22T16:33:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wokawaka](https://avatars.discourse-cdn.com/v4/letter/w/e480ec/32.png) [@wokawaka](https://forum.kirupa.com/u/wokawaka)\
**Post date:** [April 22, 2008, 4:33pm UTC](https://forum.kirupa.com/t/reaching-from-a-class/258270/1 "2008-04-22T16:33:27Z")

</div>

Hey.  
Im brand new to AS3.0 and giving the whole classes thing a go…  
Trying to detect when a button is being pressed using this class, this is giving me an error.  
The problem is im not sure how to reach the button from within the class…  
[AS]  
// on main timeline  
var buttons:buttonEvents = new buttonEvents();

// in the class  
package{  
import flash.events.Event;  
import flash.events.MouseEvent;  
import flash.display.Sprite;  
public class buttonEvents extends Sprite{  
But\_login.addEventListener(MouseEvent.CLICK, attemptToLogin);  
}  
function attemptToLogin(event:MouseEvent):void {  
trace(“button clicked”);  
}  
}  
[/AS]  
this results in  
1120: Access of undefined property But\_login.  
Which im pretty sure of is because the button ‘But\_login’ only exists on the main timeline and not in my class… so how do i reach it?

Thanks!  
P.S. it is called ‘But\_login’ on the main timeline, i am very sure.
