Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Flash General Questions > Flash 9 General Questions

Reply
 
Thread Tools Rate Thread Display Modes
Old 08-06-2007, 02:07 PM   #1
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default Document Class access _root ?

Hello there,

I just started coding ActionScript 3 with Flash CS3, I'm trying to add a event to the stage from the document class, but it never occurs (dispatch)?

PHP Code:
package {

import flash.events.MouseEvent;
import flash.display.MovieClip;

   public class 
blah extends MovieClip {
      public function 
blah()
         
addEventListener(MouseEvent.MOUSE_DOWNok);
      }

      public function 
ok(e:MouseEvent):void {
       
trace("test");
      }
}

I don't get test when I click on my mouse, the stage is empty.

thanks for any help.

regards,
Hw2002
HW2002 is offline   Reply With Quote
Old 08-06-2007, 06:26 PM   #2
dr_zeus
Flash Adventurer
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,975
Default

Have you tried this?

ActionScript Code:
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, ok);

I've found that specifically referencing the stage can have different results somtimes.
__________________
Josh Tynjala | JOSHBLOG | Bowler Hat Games
dr_zeus is offline   Reply With Quote
Old 08-06-2007, 06:39 PM   #3
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default Thanks

Quote:
Originally Posted by dr_zeus View Post
Have you tried this?

ActionScript Code:
this.stage.addEventListener(MouseEvent.MOUSE_DOWN, ok);

I've found that specifically referencing the stage can have different results somtimes.
Thanks for your help, its working.

But what do you mean by "It can have different results sometimes?", since I developing something to a customer, and I want it to work always as I excepted it to work?

I hope you can tell me what you mean and thanks again for your help
HW2002 is offline   Reply With Quote
Old 08-06-2007, 09:17 PM   #4
dr_zeus
Flash Adventurer
 
dr_zeus's Avatar
 
Join Date: Mar 2005
Location: Silicon Valley
Posts: 1,975
Default

The line of code I suggested will always work the way you expect. You misunderstood my meaning. What I ultimately meant is that your document class is not the stage. The reason your code wasn't working before is because the document class didn't contain anything that was clickable. To make it clickable, you need to draw something on it. I suggested using the stage because you can always listen for mouse events from the stage object regardless of what's been drawn.
__________________
Josh Tynjala | JOSHBLOG | Bowler Hat Games
dr_zeus is offline   Reply With Quote
Old 08-07-2007, 08:54 AM   #5
HW2002
Registered User
 
Join Date: Jan 2007
Posts: 85
Default

I actually thought the document class was the root for my whole stage, but as I understand from you, its not and I have to put events on the stage and not on my document class.

this made me thing about the _root, I used to do something like this with AS2:

_root.onEnterFrame = function():void {
}

and not stage.onEnterFrame?

Do you have the time to explain and many thanks to you
HW2002 is offline   Reply With Quote
Old 08-07-2007, 12:19 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,758
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

see "How stage, root, and MainTimeline Fit Together":
http://www.kirupa.com/forum/showthre...48#post2129548
__________________
(6)
senocular is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can't I access a Class object variable with a for..in loop from my main movie?? kosfsh ActionScript 2.0 0 05-14-2007 04:56 PM
Extendings class... simonboris ActionScript 2.0 0 02-25-2006 05:53 PM
How to access a symbol instance from a class ? seby ActionScript 2.0 7 04-01-2005 11:26 AM
Embedded Class Function Can't Access Variables gus_welter ActionScript 2.0 2 03-17-2005 08:50 PM
Inherited Properties problem with class hierarchy Johnathon_apple ActionScript 1.0 (and below) 5 09-17-2003 01:38 AM


All times are GMT. The time now is 01:11 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.