Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




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 appreciatedAttach Codefunction 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!");}}



Adobe > ActionScript 3
Posted on: 02/12/2008 03:47:51 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Movieclip Doesn't Increase Its Size When Children Are Added?
Hi, I've created a thumbnail collection class that holds (as the name suggests) all the thumbnails. I intend to use this as the source of a scrollpane so that the user can scroll down the thumbnails. Here is the code for the ThumbNailCollection class:


ActionScript Code:
package
{
    import flash.display.MovieClip;
    import flash.xml.*;
    import flash.events.*;
    import flash.net.*;
   
    public class ThumbNailCollection extends MovieClip
    {
        private var thumb_names:Array;    // all the file names of thumbnails in this collection
        private var row:int;            // counter for how many rows of thumbnails in this collection
        private var col:int;            // counter for how many columns of thumbnails in this collection
        private const START_X:Number = 25.5;        // the x coordinate of the starting point
        private const START_Y:Number = 33.5;        // the y coordinate of the starting point
        private const HORIZ_GAP:Number = 70;        // the horizontal gap between thumbnails
        private const VERTI_GAP:Number = 54;        // the vertical gap between thumbnails
        private const THUMB_W:Number = 150;   // width of the thumbnail
        private const THUMB_H:Number = 112.5;      // height of the thumbnail
       
        public function ThumbNailCollection(xml_name:String)
        {
            row = 1;
            col = 1;
            thumb_names = new Array();
            readList(xml_name);
        }
       
        // reads the list of picture files
        private function readList(file:String):void
        {
            var ldr:URLLoader = new URLLoader();
            ldr.addEventListener(Event.COMPLETE, loadingComplete);
            ldr.load(new URLRequest(file));
        }
       
        private function loadingComplete(e:Event):void
        {
            var pictures:XML = new XML(e.target.data);
           
            for(var i:int = 0; i < pictures.pic.length(); ++i)
                thumb_names.push(pictures.pic[i]);
               
            for(var j:int = 0; j < thumb_names.length; ++j)
                addThumbNail(thumb_names[j]);
        }
       
        public function addThumbNail(thumb:String):void
        {
            var t:ThumbNail = new ThumbNail(thumb);
           
            if(row == 1 && col == 1)        // no thumbnail added so far
            {
                t.x = START_X;
                t.y = START_Y;
               
                addChild(t);
                ++col;
            }
            else
            {
                t.x = START_X + (THUMB_W + HORIZ_GAP) * (col - 1);
                t.y = START_Y + (THUMB_H + VERTI_GAP) * (row - 1);
               
                addChild(t);
                ++col;
            }
           
            // if the column is more than 3, create another row and set col to zero
            if(col > 3)
            {
                ++row;
                col = 1;
            }
        }
    }
}

This works perfectly (I can see all the thumbnails being added in their correct positions). But when I set an instance of ThumbNailCollection as the source of my scrollpane, the scrollpane doesn't have a scroll bar. So I traced the size of the instance of ThumbNailCollection, and it turns out to be 0 * 0. I even tried to explicitly change the size of ThumbNailCollection whenver a new thumbnail is added, but then the size is still 0*0 and now I can't even see the thumbnails.

My questions are: Why doesn't the Movieclip class automatically adjust its size when a child is added? How can I make it adjust its size accordingly whenever a child is added?

I'm new to actionscript, so this may turn out to be a really easy, basic question so please be tolerable, and thanks in advance!

Children Referencing
I am making a Jewelry Builder, where there is a certain number of slots created at runtime, these movie clips are created in a sprite called "frames". There are two other sprites called "jb" for jewelry box, and "bracelet".

basically what needs to happen, is if you drop a bead on a slot that a bead already occupies, if the next slot over (next movieclip in the "frames" sprite) is unoccupied, the bead slides over. the problem im having is checking the ".assigned" variable assigned to the slot next to it in "frames"

With this:

trace(frames.getChildByName(event.target.dropTarge t.parent.dropTarget.parent.name).x);

i am able to get the x cord value for the slot under both both beads, but a variable declared earlier in the script ".assigned" cannot be called.

the bead you drop is the event.target, and bead you dropped it on is the dropTarget.parent, and then the frame underneath that bead is the second dropTarget.parent.

there has to be a better way to call child movie clips and access all the variables assigned to them can anyone help?

Adding/Referencing Dynamically Added Components
Is it possible to use XML as a source document to build dynamically generated components? As an example, if the XML specified to add a checkbox, then a checkbox component would be added to a pre-determined location.

What I am not sure is if the selected content for each component could then be referenced.

In other words, imagine that my XML has indicated that a check box, 3 radio buttons, and a list box should be added to the flash application. As the XML data is read into flash, each element value calls a different custom function (i.e. myCreateCheckBox).
How then do I refer to this component? Is it even possible? I was thinking it might be possible if I added the component object to an array of that component type.

Any thoughts on how I might approach this would be appreciated.

Thanks.

DisplayObject Is Not Always Added To Stage
Alright, I have another post with the same issue but this one is more isolated.

I have a simple app which adds 2 boxes to the stage. For some reason when the swf is cached the first box doesn't make it to the stage. Link to test


ActionScript Code:
package {
    import flash.display.Sprite;
    import flash.display.Stage;

    public class SampleApp extends Sprite
    {
        private var bg:Sprite;
        private var box:Sprite;
       
        public function SampleApp()
        {
            bg = new Sprite();
            bg.graphics.lineStyle();
            bg.graphics.beginFill(0x000000, 1);
            bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            bg.graphics.endFill();
            stage.addChild(bg);
           
            init();
        }
       
        private function init():void
        {
            box = new Sprite();
            box.graphics.lineStyle();
            box.graphics.beginFill(0xccff00, 1);
            box.graphics.drawRect(0, 0, 200, 100);
            box.graphics.endFill();
            stage.addChild(box);
        }
    }
}

on initial load (as expected)


after leaving the page and returning. The swf is now cached. (not expected)


Check it out for your self. I can reproduce this every time on my works fast connection.

Removing All Children From The Stage
I'm having trouble removing everything from a stage without several errors popping up... For those of you who have helped me on the other problems with my game I'll explain the details.

My generator class now generates a Life bar, a Player, Zombies, a Reticule, and Bullets. When the player dies I want all of these to be removed. I have tried code like the example below...


PHP Code:



public function checkIfPlayerDead():void
{
    if(player.getLife() <= 0)
    {
        stage.removeChild(life);
        life = null;
        stage.removeChild(player);
        player = null;
        stage.removeChild(reticule);
        reticule = null;
                  
                    
        for each(z in zombieHorde)
        {
                stage.removeChild(z);
        }
        zombieHorde.splice(0);

        for each(b in bArray)
        {
            stage.removeChild(b);
        }
        bArray.splice(0)
                
        stage.removeChild(this);
    }
}




But is has returned, as I have stated, a plethora of "can't access methods and properties of null references" and "must be child of caller" errors.

Thanks in advance.

[CS3] Apply Actions After Added To Stage
Hello again everyone...

Really appreciate all the help I've been getting here! Hoping I can rely on you guys for one more:

I have a menu Movie Clip (embedded) that consists of a keyframed animation. Once you click a main button, the animation plays and the other buttons reveal themselves within the embedded menu MC. The issue is that the buttons don't exist on the stage until it's their turn to animate, so I can't figure out a way to apply my button actions from the main timeline (as their respective targets don't exist yet).

Does anyone have a suggestion on how to add the button actions as the button MC's are added?

Detecting When A Movieclip Has Been Added To The Stage
Hello,

I am having a hard time transitioning from as2 to as3.

I have a movieclip that's created with textfields that gets populated with XML content. I then want to animate this movielclip using "tweener". The problem is the class that creates the movielclip and then populates it with data takes a time to show up on the stage. So my animation class is trying to animate something that is not there yet. So I think I need an event listener to tell me when this movieclip is on the stage. Can someone point me in the right direction? Thank you.

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?

Check For Children On The Stage At Point X,y?
Hi --

I am wondering if there is a way to determine, when the mouse is pressed, if
the mouse is over a child object on the stage or over just the "blank"
stage. Is there any way to do this?

Thanks

Rich

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!

How To Target The Method Of An Object Added To The Stage?
Hi everyone,

I have 2 classes, a ColorSample class and a tile class.
Basically what I want to do is to change the color of a tile on the stage by clicking on a colorSample object

My problem is that from the ColorSample object, I can't access the changeColor method of a tile object from Tile class that I have instantiated and added to the display list.

I have a : ReferenceError: Error #1065: Variable tile_mc is not defined when I try to call that function defines in the ColorSample class

and when I defines the var tile_mc:MovieClip; in the ColorSample class it throws me:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

I've been banging my head on the wall all afternoon, can somebody help me?

Thanks guys!

BitmapData.draw On A Not-added-to-stage Object
Hi there,
here's what's going on:
- I'm working on flex
- I'm trying to draw a UIComponent (a panel, but it doesn't matter) which is not added to stage, but I'm getting some problems to do that.

here's what I'm doing:

Code:
var p:Panel = new Panel();
p.width=100;
p.height=100;
var bd:BitmapData = new BitmapData(p.width,p.height);
var i:Image = new Image();
i.width=p.width;
i.height=p.height;
bd.draw(p);
addChild(i);
when I draw the panel (or anything else) I get a blank bitmapdata...but if I add the panel to stage and then I start drawing I can get it drawn. so, the solution seems to be:
- add the panel to stage
- draw it into the bitmapdata
- remove the panel or make it invisible
BUT, in my case I have to update the panelcomponent"thing" state so I have to redraw frequently the bitmapdata...

is there any hack rick to this?

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

Assigning Text To Object Added To Stage From Library
Hello,
In AS3, I have a clip on stage named finder, and can assign text by:


Code:
finder.theText.text = "some text";
Works great. If I then take from stage, set class as "Finder" in library, change MovieClip to Sprite in same window, then try this:


Code:
finder:Sprite = new Finder();
addChild(finder);
shows up on stage good, then


Code:
finder.theText.text = "some text";
brings up an error. Am I missing something?

Thanks in advance for the tips.

How Do I Attach A Function To A Movie Dynamically Added To Stage Through AttachMovie?
I am using the following code to attach a movie from the Library called the Display, in each instance I am loading a thumbnail. I would like to add functions to each thumbnail so that it may respond to user events such as press and rollover

any ideas? my code is below.

photos = ["photo-01.jpg","photo-02.jpg","photo-03.jpg","photo-04.jpg","photo-05.jpg","photo-06.jpg","photo-07.jpg","photo-08.jpg","photo-09.jpg","photo-10.jpg"]

countRows = 0;
countColumns = 0;
for(i=0;i < photos.length ;i++){
dname = "photo" + i;
_root.attachMovie("theDisplay",dname,(i+1),);
_root[dname]._x = (100 * countColumns)+5;
_root[dname]._y = (100 * countRows)+5;
thatNum = 14+i;
_root[dname].loadMovie(photos[i])
_root[dname]._xscale = 99;
_root[dname]._yscale = 99;
//the line below is giving me the problem.
_root[dname].onPress = function(){trace("function works!")};
countColumns ++;
if(countColumns == 5){countRows ++;countColumns = 0}
}

Listbox Doesn't Work Properly When A Tree Componet Is Added To Stage
When I have a listbox component (UI comp set 1) on the stage and then add a tree component (UI comp set 2) the listbox loses the capability to scroll to an entry via keys. The selection moves to the proper location, but the window will not scroll the entry into view.

Does anyone have a fix/solution for this? I sent a report to support a month ago, but they have not gotten back to me.

Thanks in advance


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 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.

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 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

How 2 Add Action Script To A Container Clip That Is Added To Stage As "attachMovie"
I need help!

I have created a container (as a movie clip) that serves as a scrolling text window including buttons and graphics. The AS that controls the scrolling is typically added to the container instance after it is placed on the stage--I've tried this, and it works great.

However, I'm building a GUI and I need to replace the clip with others that are selected from buttons in the scroll. Thus, I use attachMovie to add the instance to the stage.

PROBLEM/QUESTION: How do I add the AS to the container instance to control the scrolling functions? Since it is placed on the stage by AS, I cannot find a way to add the script...

How do I do this?

Here is the script I need to add:

//establish scrolling limits (for any size scroll)
//load the container's up and down scrolling functions
//the functions control the scrolling rate
onClipEvent(load) {
boundsBox=boundingBox.getBounds(_root);
boundsContent=Content.getBounds(this);
function updateUpScroll() {
Content._y+=5;
}
function updateDownScroll() {
Content._y-=5;
}
}

//watch for scrolling event (mouse click on button)
//scrolling continues while mouse button is pressed
onClipEvent(mouseDown) {
if(FEUpButton.hitTest(_root._xmouse,_root._ymouse) ) {
upScrolling=true;
}
if(FEDownButton.hitTest(_root._xmouse,_root._ymous e)) {
downScrolling=true;
}
}

//stop scrolling when mouse button is released
onClipEvent(mouseUp) {
upScrolling=false;
downScrolling=false;
}

//watch for scrolling upon entering each frame of the movie
//check scrolling limits (limits offsets are for container)
onClipEvent(enterFrame) {
if(upScrolling) {
if(Content._y<boundsBox.yMin-45) {
updateUpScroll();
}
}
if(downScrolling) {
if(Content._y+boundsContent.yMax>boundsBox.yMax-60) {
updateDownScroll();
}
}
}

THANKS!!!

How Do I Reference A Objects Children's Children?
I have a movieclip buttons_mc

it contains many movie clips that it adds at runtime.

each one of this movieclips has a textfield called num_txt.


if I try buttons_mc.getChildAt(j).num_txt.text = 5
I get an error. but I know I am referencing the movieclip correctly because I can move it my buttons_mc.getChildAt(j).y = 50;

So how do I change the objects textfield?



I can change the text when I added the movieclip:

Code:
mybtn = new btn();
mybtn.num_txt.text = String(i);
buttons_mc.addChild(mybtn);

but sometimes I need to rechange the text later....how can I do that?


THanks

Accessing Children Of Children?
Hello,

How do i access the child of a child in the display list of my flash AS3 program?

if for instance i have a container with lots of other movie clips inside, which each then have 2 children, a text field (place 1) and and a shape. (place 0)

do I go:


Code:

container.getChildAt(12).getChildAt(1).name
to retrieve the name of the text field?

any help is greatly appreciated.

thanks,

AS3: Removing Children Of Children
I have created a container movieclip called gameCanvas which I've added to the stage. I then have a large number of movieclips which have been added as children of gameCanvas. The reason I did this is because I thought that I would be able to get rid of all these children in one go by removing gameCanvas. Obviously I was wrong! gameCanvas is removed successfully, but all the child movieclips remain.

Is the only way to remove all the children of a container movieclip to loop through each one of them in a for loop?

And what happens to all those orphaned children - do they become children of their grandparent - ie. the parent of gameCanvas (in my case, the stage)?

Targeting Children Of Children
I thought i had this worked out....
menuCont is a MC on the maintimeline with 4 children... which trace correctly with the code I have below. the children are all instances of a custom class. Within each there are more children. I have tried a bunch of different combos to target these children. such as:

ActionScript Code:
menuCont.getChildAt(1).getChildAt(1).mouseEnabled = false;
but i keep getting this:
Quote:




1119: Access of possibly undefined property menuCont through a reference with static type flash.displayisplayObject.





ActionScript Code:
if (menuCont.getChildAt(1).alpha > 0) {
        imgContainer.alpha = 0;
        for (var i:int=0; i< menuCont.numChildren; i++) {
            menuCont.getChildAt(i).menuCont.getChildAt(i).x = 34;
            // this traces all 4 children's names
            trace(menuCont.getChildAt(i).name);
            // I am having trouble targeting the children of this
            if (menuCont.getChildAt(i).name == "web_bm") {
                //trace(this.target.numChildren);
            }
            //
            /*if (menuCont.getChildAt(i) is GenWorkBtn &&  menuCont.getChildAt(i).name.substr(0,1) == "w" ) {;
            //menuCont.getChildAt(1).getChildAt(1).mouseEnabled = false;
            menuCont.getChildByName("pr").getChildByName("pr");
            }*/
        }

Adding Children To Children
Just to double-check, is it possible to do something along these lines?


ActionScript Code:
mc1.mc2.addChild(mc3);

Basically I want to dynamically add a child within a child clip that has been added to a content area. Does the Display List support this?

Thanks in advance as always.

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

I Added The Url
So that you can see what I did wrong????

I hope!

http://www.angelsonmyside.com/eaglem...mac_flash.html

(((Angel Hugs)))
Donna
Very tired in Brooklyn!

.0 Added To A Number?
Hello,

I need to add a ".0" to the end of a number if there is not a fractional portion.

Example:
If I get a number like 12, I need to return 12.0
And if I get a number like12.5, I need to do nothing...

I was looking into using parseFloat(); but, I'm getting hung up on how to look for a fractional portion. and if i need to, how to add .0

Does anyone know how this can be done?

Can Alt Tags Be Added To Swf's
Can anyone tell me if you can add an alt tag in html to the embedded flash swf, In order to enhance the page for search engines.

please let me know

Evet.ADDED
I feel very strange about how the event added are dispatched. i.e.

mc.addEventListener(Event.ADDED,onAdded)

and the function onAdded is run when:

stage.addChild(mc)

which is as expected
but i also found out that it also run when:
(under the class of mc)
addChild(otherMC)

which is when anotherMC is added to mc
and most interestingly, when:
mc.play()

and it seems whenever it reaches the first frame, the onAdded run again.

[as2]last Added Thumbs
Hi i want to add on my site sth like - last added pictures. Ive got a folder with some jpg's - normal size called 1.jpg 2.jpg etc. and thumbs - 1_th.jpg 2_th.jpg etc. I want to show only last added thumbs, not original size. I dont want to link thumbs with normal sized pics or sth. This should be in one column - last, 5 added thumbs. I know that I should use createEmptyMovieclip to create 5 container mc's. And next I should load last added thumbs. but now ive got a problem. I really dont know how to do that. Because it must depend on date of adding the file. Im also using a gallery based on xml. here its his structure:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
<pic>
<image>pics/1.jpg</image>
<thumbnail>pics/1_th.jpg</thumbnail>
<title>Obrazek nr 1</title>
<caption>Opis</caption>
<url>pics/big_1.jpg</url>
</pic>
<pic>
<image>pics/2.jpg</image>
<thumbnail>pics/2_th.jpg</thumbnail>
<title>Obrazek nr 2</title>
<caption>Opis</caption>
<url>pics/big_2.jpg</url>
</pic>
<pic>
<image>pics/3.jpg</image>
<thumbnail>pics/1_th.jpg</thumbnail>
<title>Obrazek nr 3</title>
<caption>Opis</caption>
<url>pics/big_3.jpg</url>
</pic>
<pic>
<image>pics/4.jpg</image>
<thumbnail>pics/2_th.jpg</thumbnail>
<title>Obrazek nr 4</title>
<caption>Opis</caption>
<url>pics/big_4.jpg</url>
</pic>
</images>
maybe i could use this file to solve my problem? for example script will read from file last 5 <thumbnail></thumbnail>? but im not good at as so maybe you could help me?

Additional Y Value Added
When I press a button, I am trying to say if the ball is in a certain position then move it to another position... if it is in a different position then move it a different amount x and/or y... it almost work except that in the last case it finishes at 423.85... therefore should move 0 along x... actually it moves about +30 along y ?!?

button.onPress=function(){
if (ball._x = 388.85) {
ball._x += 35;
ball._y += 94;
} else if (ball._x = 98.85) {
ball._x -=325;
} else if (ball._x = 423.85) {
ball._x -=0;
}
}

HELP ME PLEASE THINK OF THE CHILDREN
Hi could anyone tell me the action script command to close the flash movie? as in shut the window completly?
thanks

Tom Soron

Children Children
Hi All,

First post so many thanks in advance for this fine website and service.

The problem i have is that my navigation is on the root timeline, and i use this to load in differnt movies with the loadMovie command (relatively simple). I am wondering though, is it possible to control the timelines of the movies i load in from the root swf? basically, i want to be able to send the movie which is loaded in, to an outro when i click a button on the root timeline. Hope this makes sense, if anyone can tell me how, or if this is possible that would be fantastic.

Cheers people.

ID Of Children
Hello ....

I have a VBox that I am dynamically adding checkBoxs to. Each checkbox has a unique ID. That works fine.

Now I need to have access to each of those checkbox's ids so I can tell which ones where checked, disable and enable them, etc.

Can someone help me with that?

Thanks

Copyright © 2005-08 www.BigResource.com, All rights reserved