ActionScript 3.0 :: Instance Won't Appear On Stage?
Jan 19, 2010Alright so I'm trying to call the instance named mcPac onto my stage using the addChild line, and everything I have tried personally has failed.
[Code]...
Alright so I'm trying to call the instance named mcPac onto my stage using the addChild line, and everything I have tried personally has failed.
[Code]...
I would like to know if there is a reason that, within an AS3 class, I would want to do something like this:
var myStageInstance:Stage;
//within an arbitrary class
var myStageInstance:Stage = stage;
myStageInstance.addEventListener(MouseEvent, someFunction);
as opposed to something that I would normally do:
//within an arbitrary class
stage.addEventListener(MouseEvent, someFunction);
There is no particular problem that I am looking to solve right now. I would just like to know if there is a reason to use one method over the other.
I am getting a stack overflow error when attempting what I believe is a very simple task. I have a class that extends MovieClip and I attempt to add an instance to the stage. WorkSamples is the main class in my fla.
[Code]...
The Sample object does get added to the stage, although it doesn't honor the x & y position I specify. I'm sure I'm failing to comprehend something simple,
I have one MC on stage with instance name "box". That MC duplicates by using this script:
Code:
duplicateMovieClip (box, newname="box2", this.getNextHighestDepth());
box2._x = xPoz;
box2._y = yPoz;
So the new MC is now called "box2".
Inside original MC "box", I have one button. After click on that button, I need to know on which MC I clicked. box, or box2. I tried to use:
Code:
trace (this._name);
But, that get me only instance name of the button.
I was just doing a menu system for a game project, as3 with Flash CS5. The navigation is build on the frame on the main timeline. When I was creating stuffs on the 3rd frame, the btns on the frame can not be called, returning "null", this is weird. With further study, I found that, if I delete a instance on frame 2, the problem on frame 3 will be solved. Then I found that giving the instance on frame 2 a name could also make things normal. What is happening? Why having a unnamed instanced on the previous frame could make the instances on the next frame "null"?
View 2 RepliesI'm using Flash CS5. I have some instances on my stage declared in the main class and I want to attach some events to them, however at the time of the main class constructor, these are declared as null.
What's the best practice for accessing stage instances? Is there an event listener I could add that will tell me when the stage instance properties have been populated?
Simple example:
public class bleepBloop extends MovieClip {
public var productName:TLFTextField;
public function bleepBloop() {
trace( productName ); // Here it is null
}
}
However, when I access productName later, it's defined.
I created four instance of movieclip on stage and named them t1_mc,t2_mc,t3_mc,t4_mc. Then I made and array and loaded them inside the array
var arr1:Array = new Array( t1_mc, t2_mc, t3_mc, t4_mc );
var names:String;
//function made to add event listener to each object
function addListner():void {
for ( var i:uint = 0; i < arr1.length; i++ )
[Code] .....
How can I refer to an instance on the stage if:
- I added it to the stage using the GUI
- I wrote its implementation in an external AS file
I can't assign it a instance name otherwise I get this error: Code: ReferenceError: Error #1056: Cannot create property myInstance on MyClassName.
From the main timeline, I am doing a menu[code]...
My scroll bar appears but when I trace stage into my ScrollBarClass this one is null trace(stage)
I`m having a silly problem with adding instance of an object to the stage two or more times. For example, this don`t work:
Code:
var temp0:SomeClass = new SomeClass();
this.addChild(temp0);
this.addChild(temp0);
Well, I know that one instance is one instance and two objects of the same class on the stage would be two instances, but still, it is what I need.
addEventListener(MouseEvent.CLICK, clickAction);
function clickAction (e:MouseEvent):void
{[code]....
for every click it will adds a new btn_mc instance on the stage..I wants to add the btn_mc instance to the stage at only once... How can I achieve this?
Does creating a new instance of an Object that uses an identical name to an older instance, delete the previous instance? Or should the original instance be deleted first? The code uses a ridiculous amount of XML vars. Isn't it less memory intensive to parse the XML and save the properties to an Object, and then delete the XML Object, rather than keep the XML Object around and reference it's child nodes directly? Is it better form to break up a huge XML file (>600lines/3200vars) into smaller chunks?
View 1 RepliesI have a main document class with another class instanciated (mouse follower.as) within it. I want the mouse follower class to access a stage instance. How is this done?
View 1 Repliesi'd like to count and get position of instance of the same type in the stage.
i have tried:
var target;
for(var item in _root){
if(_root[item] instanceof MovieClip || _root[item] instanceof TextField){
[Code]....
but it says access to property _root undefined, and instanceof deprecated
access one instance of a MovieClip on the stage (blue_mc) from within the class file of another MovieClip (red_mc).e.g. One instance of "Blue" on the stage called "blue_mc", and one instance of "Red" on the stage called "red_mc". Both symbols are linked to class files (Blue.as and Red.as).In Red.as, I set up a function to listen for a mouse down event. When this is triggered, I want to move the instance blue_mc. At the moment, though, I can't seem to get a reference to blue_mc.I've looked into the new stage and root properties, but even though blue_mc is on the stage, it cannot be accessed using stage.getChildByName( "blue_mc" ) either.
Code for Red.as:
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
[code]....
OK this has been a process but i have gotten to the point where i am calling a feedback image for the different categories, I just need to clear the foodfeedback and artfeedback children when music is pressed and the same for the others
/*import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
[code]......
I wanted to create an instance of a textField on the stage with simple text. I thought the following piece of code would work:
var textfield1:TextField = new TextField();
textfield1.text = "testing text";
textfield1.x = 300;
textfield1.y = 300;
textfield1.height = 150;
textfield1.width = 150;
textfield1.autoSize = TextFieldAutoSize.LEFT;
As far as I can tell the object is created and IS there but I have to call it somehow I guess.
I have an MC with a lot of frames on stage and it has sound clips attached to each frame.
I need to stop the sound being played when I move on to another frame on runtime, thus, I need to access the sound object which has no instance name. Right now the sounds overlap since none of them stops and after a while all we hear is jibba jabba.
I have searched for this but keep getting answers relating to the whole website resizing rather then a certain movieclip or instance etc. I am quite new to flash & action script but i get the idea & have built simple websites before. Publish HTML settings: scale "default(show all)" & have dimensions as a percent. Html & Flash. So everything looks great. I am using slideshow pro which is hidden behind what i want to be a fullscreen thumbnail grid as i couldn't figure out how to use thumbnail grid by itself. Im using it as a full-screen slide to show my photography.
I have one instance of thumbnail grid that i want to fill the browser window. When on a big monitor it doesn't expand to the sides. What code do i need so this instance can change to automatically resize fit the window/ browser/stage. (i can change it to a movieclip possibly if i need to?)
I have an FLA with a 'close button' on the stage, which is given the instance name of btnClose and runs from this class file[code]...Stage Instance Name lost when loaded
View 3 RepliesI am using this code to iterate through the contents of a movieclip which contains instances of "alien2" - my alien. I have each alien in a movieclip called squadron1. They all have their own layer and follow a motion path to recreate the attack sequence in Galaga. I can add action script to them by right clicking on them, but when I do this test below I can't call any MovieClip methods on them. It is my intention to add a function to each one via code to make it detect bullets, look for the player etc, but at the moment all I can do is add the code to each one individually on the stage.
Code:
var target;
for(var item in _root){
if(_root[item] instanceof MovieClip ){
target = _root[item];
[Code] .....
1) I have a movieclip instance on stage (simple graphical element that represents platforms for a hero to run and jump along). I have placed it on the stage with an external class engine.as and in this class it is called myPlatform and is an object of Platforms.as. The movieClip is called platforms and from a trace(myPlatform.name) the instance name is instance3.
2) I am attempting to access the properties of myPlatform in an Enterframe event loop in my character control and collision class (called hero.as)Basically here is the bit of code I am trying implement within Hero.as :
if (myPlatform.hitTestPoint(x,y,true)) { // if a platform is hit
trace("hitME");
y--;
tGravity = 0; // reset
break;
}
Here's the error that I get:
1120: Access of undefined property myPlatform
This all worked when I was writing actionscipt within the FLA file, on the timeline frame 1.I simply don't know how to access myPlatform from within the external Hero.as class! Do I need to create a variable?
I consider myself quite effiicient at actionscripting (ok not a guru) to have such problems by mistake.Anyway, my problem is that i am trying to access an MC through a buttons on rollover & rollout actions. So, the button and the MC are BOTH on the same timeline and stage, on the SAME movie clip, and they both have keyframes at the same frame. However, whenever i try to use something like
on (rollOver) {
McInstanceName.dothat;
}
[code].....
i am trying to create a new movieclip instance of Letter1 onto the stage,at the moment if i put
Code:
mc = new Letter1();
it does this, but i want to increase the number so i created a number var called letterDrop, as you can see below i tried to create a new mc using this but it doesnt seem to work, when i trace it i get Letter1 but when i try create it i get the error Letter1
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at flashgame_fla::MainTimeline/gameEngine()
[code]...
I know this is one of the most basic things, but I am having trouble adding an instance of a symbol to the stage with action script in Flash CS4. I have a "fireball" symbol and at the beginning of my code I say:
var myFireball:MovieClip = new fireball;
addChild(myFireball);
But it says : "1180: Call to a possibly undefined method fireball."
I have a Sprite in my library that is linked to a class (lets call it SomeClass), and i put on stage in Flash, and name the instance someClass. In my Main.as i then write:
var myClass:SomeClass = this.someClass;
SomeClass.as has a constructor with the same name as the class, however it require an argument. How do I pass that to the class when I made an instance of it directly in Flash by dragging it to the stage? (instead of the usual ... = new SomeClass(arg); )
I tried something like this:
myClass.SomeClass(arg);
But that gives me this error:
1061: Call to a possibly undefined method SomeClass through a reference with static type SomeClass.
In the flash IDE I have the file class com.example.NewCore. The NewCore class extends my original class named Core and the Core class extends MovieClip. What I don't understand is why isn't the original Core class able to access the assets on the stage? Or am I doing it wrong and should go about another way for inheritance. Heres alittle more back story... I had a project and it was fully developed. Now I have built another project based on that project with differently styled assets on the stage with same instance names. I needed to override a few functions but the class I extended can't access anything on the stage. I tried researching this but I can't identify exactly what I'm doing.My last guess would be to take everything off the stage and make it a class available in the library, but I don't know what the right way to do this.
View 2 RepliesI have created a movie clip on the stage and in symbol properties I have checked "Export for ActionScrip" the MC name is "slide" and the class is "slide" base class is flash.display.MovieClip.
When I test the movie I get this error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main_fla::MainTimeline/frame1()
Here is my code:
PHP Code:
var slide = getChildByName("slide"); //add instance from library?
function slideRollOver(event:MouseEvent):void {
// trace("OK");
} slide.addEventListener(MouseEvent.ROLL_OVER, slideRollOver);
im trying to grab the instance name of something on stage, set it to a variable then remove it.
iv tried:
Actionscript Code:
var something = object1something.removeMovieClip();
that works. problem is im setting variables at runtime depending on a user click.tried this too..
Actionscript Code:
var myvar;object1.onRelease = function() {myvar = this._name;}
tracing this out reveals that it is actually _level0.object1.also tried adding the string "_level0." + object1. still dosen' work.what im trying to do is click on objects. store there instance names into an array then remove them all when i do something else. such as press space.
I have a symbol called s1 in the library and I also created an instance of it on the stage on the first frame, its name is myS01Before I linked the document to a class (this was for youtube player) I was able to add event listeners, such as mousevents, onto this instance in my actions panel. But, after I linked my document to the external class in a package without a name, I cannot add any code into Actions panel, because it gives me all kinds of weird problems.Instead I am trying to use this symbol and add listeners to it in my external class file (the one linked to the document) with no luck.my external class file looks like:
package { import flash.display.Sprite; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import src.com.enefekt.tubeloc.MovieSprite; import src.com.enefekt.tubeloc.event.*;
[code]......