Referencing Stage From A Child
Hi, I'm making a test game to flesh out my AS3 knowledge. Currently, I have a main class (let's call it gameTitle) that the game runs from. I have several other classes, including GameScreen which is eventually displayed using the addChild method. The third piece of the puzzle are the game controls. This block of code contains a method that requires 'stage' as an argument (it detects keys being held down).This particular method works fine when it's a part of the main class. I want to move it to the GameScreen class, but I'm having trouble referencing the same 'stage' property from here without getting errors. I've tried parent.stage, but I get the following error message:TypeError: Error #1009: Cannot access a property or method of a null object reference.at GameScreen$iinit()at gameTitle/menuSelection()I should note that gameScreen is the class where the method is located. And this class is initiated by the menuSelection() method which is located in the gameTitle class.
Adobe > ActionScript 3
Posted on: 02/08/2008 01:26:45 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Referencing Child Mcs?
OK I know this has to be simple but I just can't get it to work.
I have a mc in my library. start_button. Inside start_button I have another movie clip quiz_color, instance name is also quiz_color. I set the linkage no problem and I can get start_button to appear via actionscript on the stage. My problem is how do I reference quiz_color?
start_button=new bStartQuiz();
start_button.x=220;
start_button.y=400;
addChild(start_button);
Now I need to get to quiz_color (to change its size, alpha, etc).
Thanks!
AS3 - Referencing Child MC's
I'm using AS 3 in Adobe Flash 9 Public Alpha.
I have a MovieClip named "RandImg" in my Library with an associated "RandImg.as" class file. I'm placing this MC on the stage during design time. This MC contains an instance of another MC with with the instance name of "mcDefault". In the constructor of my RandImg.as class file, if I attempt to reference mcDefault, I get the following error when I try to compile:
ReferenceError: Error #1056: Cannot create property mcDefault on RandImg.
How do I reference this movie clip in AS 3?
Also, if I want to remove mcDefault from memory, but keep the RandImg MC in memory, in the "RandImg.as" class file would I just call: removeChild( mcDefault ); ?
Thanks!
~JC
Referencing A Child's Method (AS3)
Hi, I'm trying to make a small card simulation that creates a pile of cards, and when I click on the deck it flips the top card over and moves it to another pile. Clicking on the other pile flips it back. I'm using Flash CS3 so can't use Flash 10's 3D abilities.
So far, I'v created a Card class (extending sprite) which draws 2 rectangles (for the front and back faces), and contains a public method flipTo(). which when called starts a tween which moves the card and flips it (by adjusting it's scaleX value to negative, and when scaleX = 0 toggling the visibility of the card's faces).
This works fine, and so I have a for loop that creates 10 instances of the Card class on top of each other (and within a sprite container called rightPile), giving me my pile. I've attached an event listener to the pile, so when I click it, it performs the onRightClicked function, which calls the top card's flipTo() method. So when I click on the pile, the top card flips. However, when I click again, the same card flips again, and I can't figure out how to make the next card flip. I've tried keeping track of the index of the current card, and using rightPile.getChildAt(currentCard).flipTo(), but I get the following error...
quote:1061: Call to a possibly undefined method FLIPTO through a reference with static type flash.display:DisplayObject.
Funny thing is that when I use
rightPile.getChildAt(currentCard).scaleX = 2;
it works fine... one by one the cards get wider when I click, so I can use getChildAt() to reference the correct object and modify its properties, but I can't call one of it's methods the same way...
I'd appreciate any advice or suggestions!
Attach Code
rightPile.getChildAt(currentCard).flipTo()
Referencing One Of A Series Of Child Clips
Here's an example of a series of MovieClips being loaded into a container clip:
for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
}
In attempting to affect one particular loaded clip, I've got this:
var dots:Array = new Array();
for(var i:int=0;i<10;i++){
var dotClip:Dot = new Dot();
dotClip.y = i*dotClip.height + 5;
holder1.addChild(dotClip);
dots.push(dotClip);
}
dots[5].x = -25;
My question is, is there a way to refer to that sixth dot without having to create an array and push all the dots into it? I'm trying to migrate from the AS2 attachMovie() . Many thanks!
Referencing Dynamic MovieClip And Their Child
I'm having a difficult time with a simple concept due to using papervision.
What's happening is I need to create a movie clip, load an image to the clip, and then make a material with this movieclip. So this movieclip is never added to the stage, it's only created in flash's memory, to be used in the texture.
So I have this for loop (i took out the papervision guts so I don't confuse anybody):
Code:
for (var i:int=0; i < 2; i++)
{
imageLoader = new Loader();
photoTextureMovieClip = new MovieClip();
photoTextureMovieClip.name = "ptmc" + i;
trace(["ptmc"+i]+"hello");
if (i == 0){
imageLoader.load(new URLRequest("image1.jpg"));
} else {
imageLoader.load(new URLRequest("image2.jpg"));
}
imageLoader.name = "imageLoad" + i;
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, showImage);
photoTextureMovieClip.addChild(imageLoader);
Now what my problem is, is getting the name of the photoTextureMovieClip, and it's child in my event listener:
Code:
function showImage(e:Event):void{
trace(default_scene.getChildByName("ptmc0"));
var myPhoto = photoTextureMovieClip.getChildByName(e.target.loader.name);
Tweener.addTween( myPhoto, { alpha: 1, time:2, transition:"easeInOutQuart"} );
}
So the newest instance of photoTextureMovieClip tweens the myPhoto child, but I can't figure out how to get all of the instances of photoTextureMovieClip to work.
I Am Adding A Child To The Stage, Adding An Event Listener To The Child. I Then Want
I'm trying to do something that seems like it should be really simple to do.
I am adding a child to the stage, adding an event listener to the child. I then want to remove the child from within the event listener.
ActionScript Code:
var newClip:NewClip = new NewClip();
addChild(newClip);
newClip.addEventListener(Event.ENTER_FRAME, newClipListener);
public function newClipListener(event:Event) {
trace("test");
}
I've tried quite a few things and nothing seems to work. The only method I know that works looks like this, but it's stupid and cumbersome and i'm sure there is a better way
ActionScript Code:
var newClip:NewClip = new NewClip();
addChild(newClip);
newClipArray.push(newClip);
newClip.myID = newClipArray.length-1;
newClip.addEventListener(Event.ENTER_FRAME, newClipListener);
public function newClipListener(event:Event) {
removeChild(newClipArray[event.target.myID]);
}
Referencing Stage From Class
Hello,
I am trying to make my first as3 class based game and so i was wondering if i could get some help. although the game wont have fancy graphics, i just would like to understand the way it works...currently, i am at a point where im getting :
1067: Implicit coercion of a value of type flash.display:Stage to an unrelated type Stage.
in my main file robot.fla, im using
var robo:robot=new robot(stage);
//var starenemy:enemy1=new enemy1(this.stage);
addChild(robo);
inside that robot.as
....
public class robot extends Sprite {
import flash.display.Stage;
private var _stage:Stage;
....
public function robot(stageRef:Stage):void {
_stage = stageRef;
...
}
amongst other things and i cant reference anything from the stage.
I think im going nuts trying to figure out how to correctly reference things to the stage. so can you take a look and guide me and tell me how i can proceed?
Attached is the zip file
Referencing A MovieClip On Stage Through XML
Hello.
I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.
I have an xml file that contains data so the swf knows what to do with the MovieClips.
Code:
//xml
<my_data>
<movie_clip1>mBuilding</movie_clip1>
<movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>
//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."
I've been trying different things, but I'm still stumped. Can anyone give me some advice?
Thanks in advance.
Problem Referencing The Stage
I'm having a problem that's got me completely baffled. I've got a swf file in which references to the stage give mixed results. When I test the file stand-alone, there are no errors. But when I load it from another swf, I get null object reference runtime errors. I'm referencing the stage at various points in the code, but the null errors occur only at one of those points. When I do
trace(stage)
from the code that lies outside of any function (I'm using free-form code, not a class) I get "null". But when I do the same thing from within a function, I get "[object Stage]". However, if I create a new function and reference stage from within it, I get "null". It seems to me that no matter where you reference the stage within a swf, it should always produce the same results. Am I mistaken?
Referencing A MovieClip On Stage Through XML
Hello.
I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.
I have an xml file that contains data so the swf knows what to do with the MovieClips.
I've been trying different things, but I'm still stumped. Can anyone give me some advice?
Thanks in advance.
Attach Code
//xml
<my_data>
<movie_clip1>mBuilding</movie_clip1>
<movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>
//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."
Referencing The Stage From A Loaded Swf
I am converting my website, which has a liquid interface, to as3 but I am still learning and I have a problem.
I have child.swf that I load dynamically into parent.swf. When I run that I get:
Quote:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Through trial and error I found that the null object is the child.swf trying to reference the stage at several places such as stage.stageWidth. If I comment all of them out it runs error free, but it also doesn't do anything. I have tried replacing the first 'stage' with other things such as 'root.stageWidth' but no dice.
I was also wonder how I can have a button in child.swf unload itself from the parent.swf?
Referencing Objects On Stage
Ok, this is a dumb question but I'm just horribly stuck.
In my script I go toframe 5, and there are several textfields and clips on stage, but I can't reference them from my code. I get an error saying the objects don't exist.
If I move the objects of stage and just move them into place later that works but I'm pretty sure there is a better way to do it.
Any thoughts or links? I've checked around google but I don't know exactly what I should be searching for here.
Referencing To Stage, From MovieClip
Hi i've got little trouble... First files: http://rapidshare.com/files/12813666...there.rar.html
And now. How i can get from starterClass.as file to stage, and move to frame 2?
Referencing A MovieClip On Stage Through XML
Hello.
I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment.
I have an xml file that contains data so the swf knows what to do with the MovieClips.
CODE//xml
<my_data>
<movie_clip1>mBuilding</movie_clip1>
<movie_clip2>mBuilding.mFloor</movie_clip2>
</my_data>
//flash
//xmlMovies is the variable contaning xml data
trace (this[xmlMovies.movie_clip1]); //correct
trace (this[xmlMovies.movie_clip2]); //"... null object or reference..."
Help Referencing Stage Elements
How do I go about referencing an element on the stage such as a Movie Clip from within a custom class that doesn't extend the movie clip itself.
For example if I have the following document class...
Code:
package classes
{
import flash.display.MovieClip;
import classes.XMLLoader;
public class DocumentClass extends MovieClip
{
public function DocumentClass():void
{
var xml:XMLLoader = new XMLLoader();
}
}
}
and this is my XMLLoader class...
Code:
package classes
{
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class XMLLoader
{
var req:URLRequest = new URLRequest("myXML.xml");
var loader:URLLoader = new URLLoader();
public function XMLLoader():void
{
loader.addEventListener(ProgressEvent.PROGRESS, loadProgress);
loader.addEventListener(Event.COMPLETE, loadComplete);
loader.load(req);
}
private function loadProgress(event:ProgressEvent):void
{
var percent:Number = ( 100 / event.bytesTotal ) * event.bytesLoaded;
}
private function loadComplete(event:Event):void
{
var newLoader:URLLoader = URLLoader(event.target);
}
}
}
If I have a dynamic text box with the instance name xml_txt inside a movie clip with the instance name xml_movie on the stage, how can I access it from within the XMLLoader class?
Referencing Movie On The Stage Error
I have a movie_clip_A and a movie_clip_A on the stage.
From a frame in movie_clip_A and using a mouse over event, i'm trying to control movie_clip_B.
I have referenced the movie clip both relative and absolutely:
this.parent.movie_clip_B.gotoandPlay(frame);
root.movie_clip_B.gotoandPlay(frame);
But I keep getting this error. When I click go to source. It jumps to an unrelated line of code all together.
The error is:
1119: Access of possibly undefined property movie_clip_B through a reference with static type flash.displayisplayObject.
What I am not doing correctly? (By the way, i have double checked my instance names and spelling)
Referencing Stage Items From Packages
Take this very basic piece of code:
ActionScript Code:
package {
import fl.controls.Button;
import flash.display.*;
import flash.events.MouseEvent;
public class ControlButton extends MovieClip {
public function ControlButton() {
setupButtons();
trace("buttons setup");
}
private function setupButtons():void {
myPauseButt.addEventListener(MouseEvent.CLICK, pauseButtHandler);
}
private function pauseButtHandler():void {
trace("-- pauseButtHandler: pause/play clicked");
}
}
}
it just traps a button click for a button component on stage.
If you instance it in the document class, directly in the fla, it works.
Instead if you instance it in another class, defined in another package, it doesn't find the button:
1120: Access of undefined property myPauseButt.
for the record, this is how I instance ControlButton:
ActionScript Code:
var cb:ControlButton = new ControlButton();
addChild(cb); // tried with and without this, same thing.
MORALE: What should I do to see a button component on stage from some remote class?
Having A Problem Referencing Objects On Stage ?
Hi everybody,
I am having a problem referencing two objects on stage and telling them to swap depths. I have an object called "illustration" on the stage that has two separate layers inside of it. These two layers hold "illustrationText" and "illustrationTextRed". My problem comes when I try to swap the depth of the two child objects (illustrationText, illustrationTextRed).
The code I placed on the timeline:
PHP Code:
illustration.addEventListener(MouseEvent.ROLL_OVER, onIllustrationOver);
illustration.addEventListener(MouseEvent.ROLL_OUT, onIllustrationOut);
function onIllustrationOver(event:MouseEvent):void
{
root.illustration.swapChildren(illustrationText, illustrationTextRed);
}
function onIllustrationOut(event:MouseEvent):void
{
root.illustration.swapChildren(illustrationText, illustrationTextRed);
}
Compiler errors keep getting thrown:
Access of undefined property illustrationText
Access of undefined property illustrationTextRed
Am I going about this the right way?
Thanks for your help!
-Brian
Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with a symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.
I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.
Under this type of linkage, is there a way to reference the stage width from the class?
I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.
Below is the code for my .fla file and my .as file. In the .as file you'll see the line "x = Math.random() * stage.stageWidth;". This is the line giving me problems. I could hard code it, as I do for the y variable on the next line, but I'd prefer not to in order to keep the code flexible.
I also attached the files in a zip.
Any help would be appreciated.
ActionScript Code:
//.fla code
var i:int;
for(i=0; i < 100; i++){
var myBall:flaBall = new flaBall();
addChild(myBall);
}
//.as code
package {
import flash.display.*;
import flash.events.Event;
public class Ball extends MovieClip{
var dx:Number;
var dy:Number;
public function Ball(){
addEventListener(Event.ENTER_FRAME, onEnterFrame2);
reset();
}
private function reset(){
x = Math.random() * stage.stageWidth;
y = Math.random() * 400;
dx = Math.random() * 20 - 10;
dy = Math.random() * 20 - 10;
}
private function onEnterFrame2(event:Event):void{
move();
checkBounds();
}
private function move(){
x += dx;
y += dy;
}
private function checkBounds(){
if (x > 550 || x < 0){
dx *= -1;
}
if (y > 400 || y < 0){
dy *= -1;
}
}
}
}
Referencing Added Stage Children
I am trying to reference a child I added named "userInfo_mc" with nested inputText named "inputEmail". But I am getting this error when compiling referencing the line inside the userInfoSubmit function :
1120: Access of undefined property userInfo_mc.
Any Ideas? Any help is appreciated
Attach Code
function individualAccount():void
{
var userInfo_mc:UserInfoMC = new UserInfoMC();
addChild(userInfo_mc);
userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OVER, showEmailInfoBubble);
userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OUT, hideInfoBubble);
userInfo_mc.continue_btn.addEventListener(MouseEvent.CLICK, userInfoSubmit);
}
function userInfoSubmit(event:MouseEvent):void
{
if (userInfo_mc.emailInput.text == ""){
trace("Fill this out!");
}
}
Referencing Stage From External Class
I have an external class file that extends the MovieClip class and is linked to a movieClip on the main stage. I need it to be able to access properties of other movieclips on the main stage. How could I do this. Here is what my base movieclip class that I want to access the stage with looks like. Remember, it is linked to a movieclip on the stage, if that matters...
Obviously there is more code in the class, but I removed it for the sake of simplicity.
Attach Code
package{
import flash.display.MovieClip;
import flash.display.DisplayObject;
import Math;
public class Test extends MovieClip{
public function Test(){ //Constructor
}
}
}
Referencing Stage.stageWidth From A Class
I created a custom class in a .as file. I then linked this custom class with an symbol from the library in my .fla file. However, I can't reference stage.stageWidth in my custom class file. I get a null object error.
I think this happens because the custom class file is associated with a symbol on the stage and not the stage itself. For example, if I set the fla file's Document Class to the name of my custom class I can reference stage.stageWidth in the custom class. But I don't do this because I am creating multiple instances of the symbol on the stage. In order to do that properly i found I have to set the class in the properties panel of the symbol to the underlying class which then defines how each symbol behaves.
Under this type of linkage, is there a way to reference the stage width from the class?
I've tried root.stage.stageWidth and parent.stage.stageWidth to no avail. I also made sure to import flash.display.* in my custom class.
Any help would be appreciated.
Referencing Author Time Buttons On The Stage?
I have some buttons on the stage that were manually placed during authoring. They all have their own instance names manually assigned already. I need to code them thru my Document Class. How do I get reference to them?
I know how to do this if I am placing them from the library at runtime, but not this way.
Thanks
Adding Child To Stage?
Inside a movieclip I have:
var _add = new websites1();
addChild(_add);
This adds a MC from my library inside the movieclip, BUT how can I get it to add it to the stage rather than inside the MC.
Thanks?
Add Child To MainTimeline Instead Of Stage
Hi.
I was wondering if there is a way to addChild to MainTimeline instead of Stage.
I created 3 instances,one after another exactly the same way, and one of them is added to MainTimeline and rest are added to Stage. why?
i have allready tried the following ways
this.addChild
addChild
this.parent.addChild
this.stage.addChild
this.root(MovieClip).addChild
etc...
but it doesn´t change anything.
thanks in advance.
scorpion9
Test If Child Is On Stage
This may be a newbie question but how would I check if there is a child of a movieclip on the stage?
When I press a button I want to use an "if" statement to check if the child/ object is on the stage, and if it is, to remove it.
Something like this, except "onStage" isn't actually a real property, what should I do instead?
ActionScript Code:
function myButtonClicked(Event:MouseEvent):void
{
if(myMovieClip.onStage == true)
{
removeChild(myMovieClip);
}
}
Thanks.
Center With Stage Child Swf
hello
I create a swf that call another swf, i use addchildAt after the preload. The first swf is center using the size of the stage, but i can do the same to the second swf. give me a error "
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at swf2_fla::MainTimeline/swf2_fla::frame1()"
I have the flas here: http://www.digisource.pt/test/flas.zip
------------------
swf1.test
I creat a mc call cub1
PHP Code:
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
addEventListener(Event.ENTER_FRAME, resizeHandler);
var aCarregar:Loader = new Loader();
carregarSwf("swf2");
function resizeHandler(event:Event):void {
cub1.x = (stage.stageWidth/2);
}
function carregarSwf(teste:String) {
var swfACarregar:String=teste;
var swfQueCarrega:URLRequest = new URLRequest(swfACarregar+".swf");
aCarregar.load(swfQueCarrega);
aCarregar.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
aCarregar.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
}
function showPreloader(evt:Event):void {
//code to control preload
}
function showProgress(evt:ProgressEvent):void {
//math of the preload bar
}
function showLoadResult(evt:Event):void {
addChildAt(aCarregar,0);
}
--------
in swf2.fla - i creat mc call cub2
-------
import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
addEventListener(Event.ENTER_FRAME, resizeHandler);
function resizeHandler(event:Event):void {
cub2.x = (stage.stageWidth/2);
}
--------------
Please help me understand the problem
Thanks
Add Child And Stage Events
Hi all
so my issue is that when my stage is resized one of my attached library items. Is side the document class called myMenu is not repositioning itself after the resize event is being called once the stage resizing event occurs.
cheers for any pointers brndn
Code:
function resizer(event:Event = null):void{
circleMenu.y = stage.stageHeight/2;
myMenu.y = stage.stageHeight/2;
}
function LOADMENU():void
{
var newMenuHolder:MenuHolder = new MenuHolder();
var myMenu = addChild( newMenuHolder);;
myMenu.y = stage.stageHeight/2;
myMenu.x = 240;
}
Detect If Child Is Outside Parent's Stage
this.createEmptyMovieClip("caption_mc", 999);
loadMovie(_parent.captionClip, caption_mc);
The size of the clip that gets loaded is variable and more often than not part of it will be offstage. I need a way to detect if it's offstage and, if so, adjust x/y & redetect.
Many thankx
--steve...
Parent And Child Stage Quality
Is it possible to have a parent movieclip using the default high stage quality for rendering yet have a child movieclip using a different stage quality like medium or low?
cheers
Listen If A Child Is Added To Stage
I want to write an if statement that will execute a function only if a child was added to the stage... But how do you go with writing that down?
Stage Not Getting Registered Inside Child Mc
Hello everyone,
I have got a heirarchy of objects which goes like this -> stage.control_mc.gaincontrol_mc.knob_mc
i am trying to register an event listener for stage from within knob_mc using
stage.addEventListener("mouseUp",this.mup2);
and i have defined the function mup2 within the knob_mc class - but when i run the movie and dynamically add the knob_mc to the stage i get this error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
i dont know why stage is a null object. when i trace stage from within knob_mc i get null....
thanks in advance..
Loader Child Swf Stage Resize Issue
Hi there,
I've exhausted Google for answers, so I'm turning to the pros...
Basically I have a loader in Main.swf and I'm loading Index.swf into it then setting the loader width/height to the full size of the users stage.
Within Index.swf I am now trying to set items on the stage according to the width/height. I've written the code to do the positioning but when I run Main.swf it throws:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Index()
What I'm wondering is...how the heck can I pass the parents stage dimensions? Second of all, if the stage resizes, how am I going to fix the position of the elements in the child?
I was thinking of two ways, but don't quite know how to do it...the first is to pass data via the loader, but where would I pick that data up in the child? Second of all using LocalConnection...but I only know how to call functions...does that mean I have to create a function in the child to receive the new dims?
Help? :-)
Adding Child To Stage On Mouse Click?
I’m having trouble with getting my head round classes & instances, I’ve gone through tons of tutorials and posts, I’m understanding more as I go but boy is it cracking my head!
I’ve uploaded a ZIP with .fla & .as files in it…
Basically I am trying my make it so that every time the mouse is clicked a new Child of an MC is added to the stage.
Can someone please take a look and put me out of my misery?
Thanks.
Removing Child From Stage Error #2025
I'm making the transition from AS2 to AS3 and I thought I had began to start thinking in the new way but now I'm stuck again.
I have a click event listener activated by clicking a movieclip. Everything works well, external swfs are loading, alpha changes working on the other movieclip buttons but as soon as I add a script to remove a child(movieclips from the other movieclip buttons) it gives me this error:
[color="black"][color="black"]
WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/Missionbtn()
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/collectionClick()
Here is my script, the 2 buttons in question are Collection button and Mission Button
ActionScript Code:
var i=new Loader();
addChild(i);
i.load(new URLRequest("flashslideshow.swf"));
i.x=15
i.y=170
var imageRequest:URLRequest = new URLRequest("about.swf");
var imageLoader:Loader = new Loader();
imageLoader.load(imageRequest);
var collectionRequest:URLRequest = new URLRequest("collection.swf");
var collectionLoader:Loader = new Loader();
collectionLoader.load(collectionRequest)
//LINKS
var blogLink:URLRequest = new URLRequest("http://www.adobe.com");
var storeLink:URLRequest = new URLRequest("http://www.ehecalt.bigcartel.com");
//
//BLOG BUTTON ************************************
blog_mc.addEventListener(MouseEvent.CLICK, Blogbtn);
function Blogbtn(event:MouseEvent):void
{
navigateToURL(blogLink);
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = 1;
collection_mc.alpha = .4;
}
//
//STORE BUTTON ********************************
store_mc.addEventListener(MouseEvent.CLICK, Storebtn);
store_mc.addEventListener(MouseEvent.ROLL_OVER, StoreOver);
store_mc.addEventListener(MouseEvent.ROLL_OUT, StoreOut);
function StoreOver(event:MouseEvent):void
{
store_mc.gotoAndPlay(2);
}
function StoreOut(event:MouseEvent):void
{
store_mc.gotoAndPlay(5);
}
function Storebtn(event:MouseEvent):void
{
navigateToURL(storeLink);
mission_mc.alpha = .4;
store_mc.alpha = 1;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = .4;
}
//
// COLLECTION BUTTON
collection_mc.addEventListener(MouseEvent.CLICK, collectionClick);
function collectionClick(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = 1;
addChild(collectionLoader);
collectionLoader.x = 15;
collectionLoader.y = 170;
removeChild(i);
}
//
//Contact BUTTON ************************************
contact_mc.addEventListener(MouseEvent.CLICK, Contactbtn);
function Contactbtn(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = 1;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
}
//
//MISSION BUTTON
mission_mc.addEventListener(MouseEvent.CLICK,Missionbtn);
function Missionbtn(event:MouseEvent):void
{
mission_mc.alpha = 1;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
addChild(imageLoader);
imageLoader.x = 15;
imageLoader.y = 170;
removeChild(i);
}
//buttonmode
contact_mc.buttonMode = true;
blog_mc.buttonMode = true;
store_mc.buttonMode = true;
collection_mc.buttonMode = true;
Removing Child From Stage Error #2025
I'm making the transition from AS2 to AS3 and I thought I had began to start thinking in the new way but now I'm stuck again.
I have a click event listener activated by clicking a movieclip. Everything works well, external swfs are loading, alpha changes working on the other movieclip buttons but as soon as I add a script to remove a child(movieclips from the other movieclip buttons) it gives me this error:
[color="black"][color="black"]
WARNING: Actions on button or MovieClip instances are not supported in ActionScript 3.0. All scripts on object instances will be ignored.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/Missionbtn()
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at mainmovie_fla::MainTimeline/collectionClick()
Here is my script, the 2 buttons in question are Collection button and Mission Button
ActionScript Code:
var i=new Loader();
addChild(i);
i.load(new URLRequest("flashslideshow.swf"));
i.x=15
i.y=170
var imageRequest:URLRequest = new URLRequest("about.swf");
var imageLoader:Loader = new Loader();
imageLoader.load(imageRequest);
var collectionRequest:URLRequest = new URLRequest("collection.swf");
var collectionLoader:Loader = new Loader();
collectionLoader.load(collectionRequest)
//LINKS
var blogLink:URLRequest = new URLRequest("http://www.adobe.com");
var storeLink:URLRequest = new URLRequest("http://www.ehecalt.bigcartel.com");
//
//BLOG BUTTON ************************************
blog_mc.addEventListener(MouseEvent.CLICK, Blogbtn);
function Blogbtn(event:MouseEvent):void
{
navigateToURL(blogLink);
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = 1;
collection_mc.alpha = .4;
}
//
//STORE BUTTON ********************************
store_mc.addEventListener(MouseEvent.CLICK, Storebtn);
store_mc.addEventListener(MouseEvent.ROLL_OVER, StoreOver);
store_mc.addEventListener(MouseEvent.ROLL_OUT, StoreOut);
function StoreOver(event:MouseEvent):void
{
store_mc.gotoAndPlay(2);
}
function StoreOut(event:MouseEvent):void
{
store_mc.gotoAndPlay(5);
}
function Storebtn(event:MouseEvent):void
{
navigateToURL(storeLink);
mission_mc.alpha = .4;
store_mc.alpha = 1;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = .4;
}
//
// COLLECTION BUTTON
collection_mc.addEventListener(MouseEvent.CLICK, collectionClick);
function collectionClick(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha =.4;
collection_mc.alpha = 1;
addChild(collectionLoader);
collectionLoader.x = 15;
collectionLoader.y = 170;
removeChild(i);
}
//
//Contact BUTTON ************************************
contact_mc.addEventListener(MouseEvent.CLICK, Contactbtn);
function Contactbtn(event:MouseEvent):void
{
mission_mc.alpha = .4;
store_mc.alpha = .4;
contact_mc.alpha = 1;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
}
//
//MISSION BUTTON
mission_mc.addEventListener(MouseEvent.CLICK,Missionbtn);
function Missionbtn(event:MouseEvent):void
{
mission_mc.alpha = 1;
store_mc.alpha = .4;
contact_mc.alpha = .4;
blog_mc.alpha = .4;
collection_mc.alpha = .4;
addChild(imageLoader);
imageLoader.x = 15;
imageLoader.y = 170;
removeChild(i);
}
//buttonmode
contact_mc.buttonMode = true;
blog_mc.buttonMode = true;
store_mc.buttonMode = true;
collection_mc.buttonMode = true;
If someone could help me get to the bottom of this and help me understand where I went wrong I'd be extremely grateful.
In Javascript - Check If A Child Has Been Added To The Stage?
Hi,
Is it possible to check, using Javascript and without altering the ActionScript code at all, if a child has been added to the stage? I have in mind something like being able to call GetChildByName in Javascript, and if the child exists, call another javascript function.
Thanks for any ideas!
Accessing Stage Level Variables From Child.
I have a child that I added during run time. I would like it to access a variable that was defined on the stage. npFurn:Number.
Everything I've tried doesn't seem to work.
stage.npFurn
parent.npFurn
MovieClip(parent).npFurn
root.npFurn
And various combinations of those. What is the correct syntax?
Swap Children Of Stage From Inside A Child
I have 9 movie clips which are all of the same object, they get larger or smaller as the mouse gets closer to their respective centers. The functionalilty for this is in an AS3 class file that extends flash.display.MovieClip.
How do I go about swapping depths so that the largest one is in the foreground, I am new to AS3 and dont seem to be able to find a way of getting the depth of the movieclip I am currently inside (this) and if I try to access the stage to call swapChildren I get the following runtime error:
The supplied DisplayObject must be a child of the caller
Any suggestions??
Regards
Rob
Having A Child Detect When The Mouse Leaves The Stage
I'm using the following to detect when the mouse leaves the stage, which is working fine until I try to add my movie as a child inside another swf when preloading. Then it breaks with a runtime error. I've tried playing around with adding the eventlistener to the parent stage, but can't see to get it to work.
Any advice?
Thanks.
Code:
stage.addEventListener(Event.MOUSE_LEAVE, hideMe);
Call A Function On Stage From Within A Child MovieClip?
Easy but not able to get it working. I have a clickable mc within another mc which is located on the main timeline. I need to call a function on the main timeline from within the clickable mc... this.parent.parent returns errors...
What am I doing wrong?
Any help?
Thanks...
Calculate The X/y Of A Rotated Child Object Relative To Stage
Sorry for the long title, but i couldn't make it any shorter.
In fact i need to calculate the x/y position of a child object of a rotated child object of a rotated displayObject.
Things like this don't work.
ActionScript Code:
object1.object2.object3.x
//0
So i figured out i need to use the localToGlobal function, but i can't get it to work, because i can't get the point object in the last object, no matter how hard i try.
So? Any suggestions on how to do this?
Edit: I already found it out. It's:
ActionScript Code:
var pt1:Point = new Point(0,0)
object1.object2.object3.localToGlobal(pt1)
Movieclip Referencing Another MovieClip On Stage
Hi all,
I have a movieclip with dynamically loaded content in a movieclip that sits on the stage, which works fine, it loads the content fine. Call it Clip A
I want multiple movieclips to reference this movieclips content. ie I want a copy of this Clip A to appear in multiple movieclips.
Real example
Clip A loads teamshirt Arsenal
Multiple clips to also have Arsenal teamshirt by looking at ClipA
Any ideas? Do i go about it using loadMovie and pointing it to the scene or attachMovie?
thank you in advance
Jason
Oop Question: A Simple Way To Access Methods In Child Classes From Other Child Class
hi All, I have another oop question.
I'd like to call a method in a child class from another child class.
I'd like to do it without instantiating the other child class...
an example will be easier to see what I mean
document class
ActionScript Code:
package
{
import flash.display.*
public class Tester extends MovieClip
{
var ch1:Child1;
var ch2:Child2;
function Tester()
{
ch1 = new Child1();
ch2 = new Child2();
}
}
}
child 1
ActionScript Code:
package
{
class Child1 extends MovieClip
{
function Child1()
{
trace("Child1 is working");
}
public function hello()
{
trace("Child1 Hello function")
}
}
}
child 2
ActionScript Code:
package
{ import flash.display.*
class Child2 extends MovieClip
{
function Child2()
{
trace("Child2 is working");
//Tester.ch1.hello();
}
}
}
the commented line in Child2 is what I'm asking about. is there any way to do this without defining the Tester class in Child2?
... I mean, without saying : var tstr:Tester = new Tester(); in Child2... and then calling the function via tstr.hello();
thank in advance guys..
Stop FLV Playback In Child When Removing Child (or At Least Silence Audio)
I'm working on a flash site with a number of different "states" (home, features, demo, etc.) each of which is a movie clip with its own actionscript, added as a child when requested, removed when the user chooses a new state.
One of the states plays short FLV videos. The problem is, when switching away from that state to a different state, even though the child is removed, the current video apparently keeps playing as I can hear the audio continuing on.
To demonstrate, the site is here. Click on "Demo", then play one of the videos and switch to a different state (home, features, whatever) while the video plays.
I'm trying to call a function in the child to stop video playback (first checking whether the function exists before trying to call it). The checking part works, but the function call is giving me a "call to possibly undefined method" error when publishing. Probably because I'm calling it the wrong way.
Here's the "remove child" code used after switching to a new state:
Code:
var child:DisplayObject;
while(stateContainer.numChildren > 1)
{
child = stateContainer.getChildAt(0);
if ('stopPlayback' in child)
{
trace('exists');
child.stopPlayback();
}
else
{
trace('does not exist');
}
stateContainer.removeChildAt(0);
}
Can you tell me a better way to do this? I find it strange that it traces "exists" when the function exists, but still complains that child.stopPlayback() (might not) exist.
Variables Of A Child Not Visible To A Function In The Child Called From Its Parent ?
sorry, this is a repeat thread, but couldn't change the title on the old one, someone must know the solution to this problem, I just dont think i worded it correctly enough for someone who knew what i was talking about to notice last time.
Ive got a movieclip that creates and adds a child mc then calls a function in the new mc. the function runs, but the local vars for the new mc aren't visible to the function. Is there a special way to call a function so that its scope is in the child, not in the parent ? ( i assume thats where it is, even though a trace of this returns the correct object type )
ie:
[Parent Clip]
--[child clip: movGraph]
--variable ( var thegraph:MovieClip = this; )
--[function loadMe]
--(trace (theGraph); )
calling movGraph.loadMe spits out undefined or null object error, as opposed to
[object movGraph]
obviously i want to do a whole lot more than trace out the object type, and trace(this) in the function returns [object movGraph]. the variable "theGraph" declared in the child isn't available or its null somehow.
Can anyone tell me where I'm going wrong ? - any help would be appreciated. at the moment I'm having to add all the code in the function instead of the "root" of the child. which really defeats the point.
|