ActionScript 3.0 :: Classes "stage" And AddEventListener?
Dec 3, 2006
I have an AS3 class that extends sprite. In the class, I create a bunch of Shape objects and add them to the stage..I'd like to change how they look when the mouse moves over them.If I use addEventListener to one of the Shape objects, the specified function is never called...but when I use addEventListener to the instance itself:
The function is called outside of the boundaries of the shapes, as if the class' stage is larger than the shape objects. That's probably the case, but I can't resize it because (1) I can't access the stage (stage is null) and (2) if I resize the instance's height it shrinks the shape objects as well...
I created an FLA file that has a control bar (with play, pause, etc.) that I want to appear only when the mouse is moved onto the stage. When the mouse is moved off the stage, I want it to fade.I used the code below but it seems that the MOUSE_OVER event is only captured when the mouse is moved over some object on the stage. When the mouse is over an unused part of the stage, the event is not fired and the control bar remains invisible.barBg_mc is the name of the control bar in the code below.
I just wanna add an image from my library on the stage and have an event listener on it so when i click on it, it will do something. imgFromMyLib is already set to the image i want from my library.
When i call stage.addEventListener from Document Class (i.e. the entry class to the program) it works. But now i have changed the structure to something like: Document Class pulls PlayScreen (which is of type movie clip). In this PlayScreen, i call stage.addEventListener, but it gives me error saying: Cannot access a property or method of a null object reference. so how do i go about it. basically, i want to add a stage event listener for keyboard event.
If I have the following code which adds an event listener to the stage, why does it not respond when the capture parameter is set to true. It works fine when it is set to Target and Bubblig (false). My understanding is that all the phases happen...
I have the following in a class and get an error message. CaseStudyQuiz is my constructor method. I want to detect when the mouse moves via the stage.addEventListener.
Is there a way to listen movie clips itself for keyboard events instead of stage.addEventListener ??I work on a project a kind of game and ı need mymovie clips on stage rotate with keyboard events such as KEY_DOWN key.code LEFT or RIGHT.I tried to add event listener my MC but it didn't work.If I listen to stage every Movie Clip in my stage start rotation same as the others.What should I do? Here is my codes
I am on my second big AS3 project and I need a better way of adding Display Objects to the main stage from within other classes.
I have my Main.as which starts everything off and is an extension of MovieClip. I have a LevelManager class which I have to load levels, track level progress, and switch between other levels of my game.
I have a Level class which has partly the duty of populating the assets to the screen for that level of the game. However, I can't just add them to the stage like I can in the Main class. (obviously)
My previous solution was to pass an instance of Main's stage through multiple classes until it got to the one who's job it was to populate display objects. It still makes me cringe.
I am having is trying to add objects to stage. At the moment I can not put anything onto the stage unless it is in my Main document class (Main). How would I add to stage in my player class and bullet class?
Code: package game{ import flash.display.*; public class Main extends MovieClip{
I'm aware that ActionScript 3.0 is designed from the ground up to be a largely object-oriented language and using it means less or even no timeline code in Flash documents.I'm quite experienced with OOP and am comfortable writing classes. However, since I mostly use Flash for animations, I hardly ever need to write ActionScript code other than for preloaders, subtitles, quality controls, website links and so on. In fact, I still set my Flash movies to use AS2 to this day because I'm used to gotoAndPlay()/gotoAndStop(), AS2 preloaders, subtitles, quality controls and even getURL(). Of course, I really want to move on now that practically everyone's on Flash Player 9 or 10 and now that I've dabbled with other OO languages like Java, C# and Objective-C too.
I'm a complete newcomer to AS3 and am not very learned with AS2 either. Considering my current use of ActionScript, are there any cases where it's still OK to use very simple AS3 code in the timeline instead of moving code to a class, especially since moving to a class might mean unnecessarily increasing the number of LOC from 4 to 40?
- I have a player.as with code to control playback of videos - I have a skin.as with code to control and organise skin components - The skin.as file loads a "shared library" (quotes as I don't think I'm doing this correctly) which is essentially a swf file with nothing on the stage. It's library contains things like: play buttons, scrub bars etc. all these assets have associated, linked class files to add functionality.
1. Load the containing swfs 2. Create new instances of the linked classes 3. Add them to the stage to be used.
However, there is an issue preventing me from using the linked assets in this way - I can't use the linked assets unless- - I add something to the stage of the "shared library" swf - I then do something like skinSwf.addChild(libraryFile) What I want to do is just use the linked assets, not have to deal with any other parts of the "shared library" file.
I'm new to as3 and although I am able to build classes that don't error but also don't put anything on the stage. I have Starter_1.as file stored in a folder called com...this is the script for that file:
Code: package com { import flash.display.Sprite; import flash.text.TextField; public class Starter_1 extends Sprite { private var tField:TextField; public function Starter_1 () { [Code] .....
From what I can see the problem is because the addChild(tField) is not referencing the stage in anyway because the script is in an external .as file and not on the timeline (good coding practice I read somewhere?) I use this on the timeline to try put the text field on the stage: Code: import com.Starter_1; var f1:Starter_1 = new Starter_1(); How do I get this working?
Access stage objects (like Movie Clip or text fields) from sub classes.The problem came when I define a subclass and try to access stage objects. How can I do that?Imagine I have a movie clip named redBox_mc on the stage.I want to change it`s alpha after I get my xml loaded.(or any other action in subclass)
Main class:
package src{ // .. public class code01 extends MovieClip { public var rt:xmlReader = new xmlReader("art.xml"); // my subclass
I am making a video player class that will be imported as a custom class into a fla (not document class). how i can add clips to the display object without having to return them from the class?
is there something like stage.addChild or root.addChild or something that i can use?
Im trying to create a class which can access a movie clip on stage. I've searched many forums/google cant seem to find the solution im after. If i have a movie clip on stage with instance name 'mc1' for example. how can i access this movie clip from a class im creating. Eventually id be able to access the movieclip via a dynamic name but need to get past this simple stage first.
Im trying to get used to packages and classes in AS3. Im used to put all code on the first frame of the timeline, but now i have 442 lines of code on the first frame. Yeah 442. And this is for a game engine so i thought i should put it inside some classes to make it easier to read an reusable. But i have noticed that if i create a class called Code and make a instance of that class like this:[AS]var codeObject:Code = new Code();[/AS]i get a bunch of errors because the class cant Acess the stage and the display list.i found a workaround by linking the class to a movieClip and and do this:[AS]MovieClip(parent);[/AS?
I have been trying to reference to the stage from outside Document class and tried many different ways I found on google and it seems none of them works (maybe there were some changes in flash since they were posted.For example TopLevel approach by Senocular doesn't work either I do it as described in here.URL...The only way it seemed to work is by passing a stage as a variable. Has anyone any idea of a way to do it without the need of passing it by.
I'm developing my first flash app. I'm trying to use classes because they'll be very important in my future app. I created a simple movieclip with a star. However, instead of putting it directly on the stage, I'm calling it from library, using the addChild method to place the star in the stage. To do that, I simple right click over the movieclip icon->properties->check export to action script->and I give a name to the class (for example: myMC)
Then, inside the class I wrote: package { import flash.display.*; import flash.events.*; public class myMC extends MovieClip { var star:myMC=new myMC(); public function myMC() { [Code] .....
As I am placing the two variables origin_x and origin_y inside the constructor, I'm expecting to get 250 and 200 respectively. After drop the star, I want to send it to it's original place, and that's why I need to keep this values. And here's the problem, origin_x and origin_y are both ZERO, instead of 250 and 200... The value is not relative to stage. I managed a little bit and I found this post : [URL]. Unfortunately I tried to replace by the suggested code, but both values remain zero. An interesting thing, is that if I put the star directly in the stage instead of calling it from the library as I am doing, I get correct values in origin_x and origin_y.
I have a Flash file for an xml driven menu. There is the document Class, called Main. There is also a Navigation class. In the Navigation class, I position the location of main buttons and sub menu buttons for the menu. I want to position the buttons in the Navigation class relative to the stage. Currently, they are just fixed at certain positions (like 20); To do this, I have read that because this is not happening in the document class.
I must add an event listener to the constructor that listens for the added to stage event. I am not sure how to do this, as when I try and add an event listener for added to stage in the Navigation class nothing happens, (or all menu items diaspear). How to position movie clips relative to the stage (i.e. stage.stageWidth - 50) from a class that is not document class? How to do so in the document class, too.
[code]Also pass the Stage reference still it not showing any error and text box is also blank,text is embed ed and the code is.[code]If I put import flash. display. List; it shows an error 1172: Definition flash.display:List could not be found.
I found this code for a contact form at msinghinteractive easy-to-use-flash-as3-contact-us-form-class and it dynamically creates input fields and buttons. I didnt like the dynamically drawn submit and reset buttons, so I added my own MCs(my 'buttons') to the stage. I tried modifying the code and took out the dynamically drawn buttons..However, I cant figure out how to add Event Listeners to the buttons which exist on the stage--Im getting undefined errors...The fla is directly associated to a main.as class which just determines the parameters of the .as class it is tied to -to set the size of the Contact form.This is the entire class:
where btn is the instance name of my submit button MC.My problem is that because my buttons exist on the stage I dont know how to add Event listeners within that class---or rather doing that doesnt work because the listeners are throwing that undefined property errors--I gave them instance names...
I having trouble nesting classes then calling them on the main stage.I have one AS file that contains all the functionality to create a simple button with a text field that can be customized from the FLA file. I want to use this AS file to create another AS file for a form.I have called the simple button from the AS file into my other AS using import RoundRectButton.
I am using Gaia framework with a fluid layout at here is what I get
This is the error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at com.gaiaframework.FluidLayout::FluidObject/reposition()
This is my first attempt at external as classes and I can't get them right. I've a button set up on the stage and an external as file with the following code:
Code: package { import flash.display.*; import flash.events.MouseEvent.*; import flash.display.SimpleButton.*; public class myTasteButton extends SimpleButton { [Code] .....
Basically I need to link an external class to the button, which will in turn when clicked play the beat_mc. I've given the button the class of myTasteButton. It's not working but I'm not getting any errors.