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




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.



KirupaForum > Flash > ActionScript 3.0
Posted on: 06-24-2008, 01:56 PM


View Complete Forum Thread with Replies

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

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

About Referencing Objects And Copying Objects
This is for AS1

hi,

i should know this but i got lost for a bit, can someone make this clear:

i have the following:

code: myobject=new Object()
myobject.var="hello"
getvar=myobject.var

In this case, get var has a reference for myobject.var, or it has just copied de value? mean if i update myobject.var to "good bye" get vatr will be that, too, or will stay as "hello".

If it's just a reference, how can make it a different variable, i mean, assign the value of myobject.var to getvar and loose any relationship between myobject.var and getvar, so if i update one, the other doesn't.

Anyone?

Referencing Objects In A Different SWF
I'm attempting to create my first all-Flash web site. I have a master SWF that will load other SWFs into movie clips or levels.

One of the SWFs I plan to load is a complex menu system. When certain buttons in the menu are selected, I want things to happen in the master SWF file (i.e. other SWFs and text files load). Is there a way to reference objects in the master SWF from the menu SWF? Or is there a way to reference objects in the menu SWF from the master SWF? If both are possible, which way is better?

Referencing Objects
Is there any way to refernce multiple objects with similar names using a loop?

eg button1, button2, button3
code:
for (i=1; i<=3; i++ ) {
button(i)._visible = false;
}

Referencing Objects From AS2 Swf Into AS3 Swf
I load AS2 swf into AS3 swf.
Is there a possibility to reference Document Class methods or properties from external loaded AS2 swf?


Cheers,

[AS2] Referencing Objects
I have an object called H with a property of mc set equal to hero:


ActionScript Code:
var H:Object = new Object();
H.mc = "hero";


the property mc holds the name of the movie clip the object H deals with

I am trying to retrieve the y coordinate of the movie clip here
I have tried the following but it dont work


ActionScript Code:
function Move(Object) {
trace( this[Object + ".mc"]._y );
}
 
Move("H");

Referencing Of Array Objects
Hello!
I don't know how many ties I've had this d*mn problem but it never fails - I can't get it to work. Lemme tell you what I am TRYING to do.

I have an array that randomly generates numbers (14). No problem. I call the array alpha cause it controls alpha levels and such (this doesn't matter). I also have a MC on the stage called mc_oval. After each loop (14 of them) - count has one added to it. I want to be able to able to duplicate the mc_oval MC and call each new MC "mc_oval" + count. Each new level is count +1 (so we don't replace level0.

the problem comes when I go to position the dynamic clip. Here is my code:


Code:
n = 14;
count = 0;
alpha = new Array();
while (count<n) {
alpha[count] = randomNum=Math.round(Math.random()*99+1);
//
duplicateMovieClip (_root.mc_oval, "mc_oval_"+count, count+1);
setProperty ("mc_oval_"+count, _x, "25");
count++;
}
Now I have tried this eval() sh*t but it works werid and doesn't fix the problem. I've tried:

eval("mc_oval_" + count);
and
"" + eval('mc_oval_' + count);

I'm lost - please help me!

Referencing Objects Via An Array
hello

i am trying to create a fake email inbox for an eLearning simulation. the brief is thus:

the inbox lists emails. emails are added as the user progresses through the game. for each email, its variables are displayed (from, subject, date received).

i have an array to store the emails in, and an index to keep count:


Code:
// Keeps track of number emails so that they can be put into an array
//and referenced.
emailCount = 0;

// Array to store emails in.
emails = new Array();


i have a constructor to create a new email object:


Code:
function email(newID, newFrom, newSubject, newBody, newDate) {
ID = newID;
emailCount ++;
from = newFrom;
subject = newSubject;
body = newBody;
thisDate = newDate;
read = false;
emails.push(ID);
}


i also have a function to display the emails:

Code:
displayEmails.onPress = function() {
for(i = 0; i < emails.length; i++) {
attachMovie("emailListMember", ["emailListMember" + i], i);
with(["emailListMember" + i]) {
from = _root.emails[i].from;
subject = _root.emails[i].subject;
thisDate = _root.emails[i].thisDate;
ID = _root.emails[i].ID;
_x = 30;
_y = 30 * i + 10;
}
}
}


after creating a couple of email instances, and trying to display them, i find their variables are not set. i think its because the array values do not point to the email instance itself, and merely holds a string.


cheers in advance

Dynamically Referencing Objects
I have generated movie clips with nested textboxes inside inside a dynamic for loop (.createEmptyMovie and .createTextBox).I do this by generating a name with the counter added to it ("mc" + x or 'txtbox" +x) -- Which generates (mc1, mc2,..., txtbox1, txtbox2,...)

I am having troubles trying to reference these individual objects with in the loop to set a value to them (_root.mc[x] and _root.mc[x].txtbox[x]). This attempt doesn't work. If I hard code a number in place of the "[x]" my code runs correctly. I am trying to reference them dynamically because I am reading from a file that could be any length long and I do not want to have to update the fla file any time a new item is added.

Does anyone know how if I could possibly get these objects referenced dynamically or if you need a definite reference to the objects? Thank you

[F8] Referencing Array Of Objects
Ive done this before, but I forget teh notations. I have objcts date1,date2..... save as a movieclip dateBoxes. I cant remember how to referencec them, say, in a for loop.

for (i=0; i==10; i++) {
dateBoxes.["date" + i].text = i;
}

Like that but it has to work lol.

thanks in advance.

Two Objects Referencing Same Array?
I'm working a neural network project and my basic architecture is this:
1. Neurons
2. Neuron Layer (basically an array of neurons)
3. Neural Network (basically an array of Neuron Layers)

When I reference the first Neuron Layer's array.length it gives me the total number of neurons in the network rather than what the number of neurons in the first layer should be. The same thing happens for the second layer and each subsequent layer should there happen to be more. I've added trace statements to the Neuron Layer constructor that tells me a neuron has been added and I've also added a trace statement after the first neuron layer is added and the second neuron layer and I get the correct number of "neuron added" statements before the "first layer added" statement and the correct number for the second layer as well. This pretty much assures me that the actual number of neurons in each layer is correct when the first layer is created but somehow the number of neurons in the first layer and subsequent layers is actually becoming the number of neurons total. The only thing I can figure out is that somehow, the first neuron layer object is referencing the same neuron array member as the second neuron layer object. Is this possibly what is happening?

Here's the code for the Neuron Layer class:

Code:
import Neuron;

class NeuronLayer{
//number on neurons in layer
private var numNeurons:Number;
//array of neurons
private var neurons:Array=new Array();
//number of inputs per neuron
private var numInputsPerNeuron:Number;

//constructor
public function NeuronLayer(numOfNeurons:Number,numOfInputsPerNeuron:Number)
{
numNeurons=numOfNeurons;
numInputsPerNeuron=numOfInputsPerNeuron;
for(var i=0;i<numNeurons;i++)
{
var neuron:Neuron=new Neuron(numInputsPerNeuron);
neurons.push(neuron);
trace("Adding Neuron");
}
}

//function to get the num of neurons in layer
public function getNumNeurons():Number
{
return numNeurons;
}

//function to get the num inputs per neuron
public function getNumInputsPerNeuron():Number
{
return numInputsPerNeuron;
}

//function that returns a copy of the neuron array
public function getNeuronArray():Array
{
var neuronArray:Array=new Array();
neuronArray=neurons.slice();
return neuronArray;
}
}
And here's the code for the Neural Network Class:


Code:
import Neuron;
import NeuronLayer;

class NeuralNetwork{
//number of inputs for network
private var numInputs:Number;
//number of outputs for network
private var numOutputs:Number;
//number of hidden layers
private var numHiddenLayers:Number;
//neurons per hidden layer
private var numNeuronsPerHiddenLayer:Number;
//array of neuron layers
private var neuronLayers:Array=new Array();
//activation response constant
private static var P_SETTING:Number=1;

//constructor, initializes private members for this class and call createNet
//function
public function NeuralNetwork(inputs:Number,
outputs:Number,
hiddenLayers:Number,
neuronsPerHiddenLayer:Number)
{
numInputs=inputs;
numOutputs=outputs;
numHiddenLayers=hiddenLayers;
numNeuronsPerHiddenLayer=neuronsPerHiddenLayer;
createNet();
}

//function that gets the number of inputs
public function getNumInputs():Number
{
return numInputs;
}

//function that get the number of outputs
public function getNumOutputs():Number
{
return numOutputs;
}

//function that gets the number of hidden layers
public function getNumHiddenLayers():Number
{
return numHiddenLayers;
}

//function that gets the number of neurons per hidden layer
public function getNumNeuronsPerHiddenLayer():Number
{
return numNeuronsPerHiddenLayer;
}

//function that returns a copy of the neuron layer array
public function getNeuronLayerArray():Array
{
var neuronLayerArray:Array=new Array();
neuronLayerArray=neuronLayers.slice();
return neuronLayerArray;
}

//builds network from neurons
private function createNet():Void
{
//create layers of network
if(numHiddenLayers>0)
{
//create first hidden layer
var firstHiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numNeuronsPerHiddenLayer);
//push it into the neuron layer array
neuronLayers.push(firstHiddenLayer);

trace("Added first layer");

//create other hidden layers as necessary
for(var i=0; i<numHiddenLayers-1; i++)
{
var hiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numInputs);
neuronLayers.push(hiddenLayer);

trace("Adding Additional layers");
}

//create output layer
var outputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numNeuronsPerHiddenLayer);
neuronLayers.push(outputLayer);

trace("Added output layer");
}
else
{
//create output layer
var defaultOutputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numInputs);
neuronLayers.push(defaultOutputLayer);
}

}

//function that returns all the weights in the network as an array
public function getWeights():Array
{
var weightArray:Array=new Array();
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
weightArray.concat(neuronLayers[i].getNeuronArray()[j].getWeights());
}
}
return weightArray;
}

//function that returns the total number of weights in the network
public function getNumWeights():Number
{
var total:Number=0;
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
total+=neuronLayers[i].getNeuronArray()[j].getWeights().length;
}
}
return total;
}

//replaces old weights with new weights
public function putWeights(weights:Array, newWeights:Array):Void
{
//empties array that's passed
weights=[];

weights=newWeights.slice();
}

//sigmoid response curve applier
public function applySigmoid(activation:Number,responseSetting:Number):Number
{
return 1/(1+Math.pow(Math.E,(-activation/responseSetting)));
}

//calculate outputs from set of inputs
public function update(inputs:Array):Array
{
//stores the resulting outputs from each layer
var outputs:Array=new Array();

var weightCounter:Number=0;

//check for correct number of inputs
if(inputs.length!=numInputs)
{
//just return empty vector if incorrect
return outputs;
}

//for each layer
for(var i=0;i<numHiddenLayers+1; i++)
{
if(i>0)
{
//copies elements into the array
inputs=outputs.slice();
}

//clears array of values
for(var a=outputs.length;a>=0; a++)
{
outputs.pop();
}

weightCounter=0;

//for each neuron sum the inputs*corresponding weights
//throw the total at the sigmoid function to get the output
for(var j=0;j<neuronLayers[i].numNeurons;j++)
{
var netInput:Number=0;

var numOfInputs:Number=neuronLayers[i].neurons[j].numInputs;

//for each weight
for(var k=0; k<numOfInputs-1; k++)
{
//sum of the weights*inputs
netInput+=neuronLayers[i].neurons[j].weights[k]*inputs[weightCounter++];
}

//add in the bias
netInput+=neuronLayers[i].neurons[j].weights[numOfInputs-1]*-1

//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push(applySigmoid(netInput, P_SETTING));

weightCounter=0;
}
}
return outputs;
}
}

Referencing Objects Within MovieClips
Hey guys, I need some help. I'm new to Flash/Actionscript and what I'm trying to do seems like it should be straight-forward and very common, but for the life of me I can't figure it out.

I've created a MovieClip in the Flash editor called 'MyClip'. As part of this movieclip there is some dynamic text.

I've also defined an ActionScript class for MyClip that inherits from MovieClip. In it there is a member function DisplaySomeText(myText:String). How can I get this function to set the dynamic text that is part of my movieclip?

At first I thought I could just give the dynamic text an instance name (say 'MyTextField') and go:


Code:
public function DisplaySomeText(myText:String)
{
this.MyTextField.text = myText;
but that doesn't work.

How the heck do you do this??

Thanks in advance for any help,
Oliver

Referencing Duplicates From Other Objects...
...is there a way to do it? If so, say I have two movie clips A and B, and I've made duplicates of A. How can I reference each A from:
1. Any of the other A duplicates? and
2. The B movie clip?

What is the scoping syntax for that? I tried to use _root.{the name of A duplicate}.{property} for accessing A from B but it didn't seem to work.

Create Array On Stage, Mathematically Referring To Objects On The Stage
Ok what I want to do is create a set of small images on the stage and name them sequentially like you would an array, then refer to them mathematically in actionscript. I tried naming them as an array but it says that the name is reserved for the system or something. Does anyone know how to get an array of objects onto the stage, or have an idea of something else I could do to get the same effect?

Create Array On Stage, Mathematically Referring To Objects On The Stage
Ok what I want to do is create a set of small images on the stage and name them sequentially like you would an array, then refer to them mathematically in actionscript. I tried naming them as an array but it says that the name is reserved for the system or something. Does anyone know how to get an array of objects onto the stage, or have an idea of something else I could do to get the same effect?

Referencing Objects On Separate Timelines
If I have a dynamic textbox that exists only on the last frame of a movieclip and I need to set the text for it from the main timeline, how would I reference it? I tried referencing it by going mc.hint_mc.hintText_txt.text = "Bla" but that doesn't work and I realized that could be because the textbox only exists on one frame of the movieclip. Is there a way to do this?

Referencing Objects Created By Functions
Hi, I've been using Actionscript 2 for a while, bit of a newbie with 3 (and objects and classes etc.) though, so I'm just running into small issues from time to time I'm completely confused by. :|

So I have a function, called initMainMenu that includes all the code for creating a menu, which is a list of movie clips inside a container movie clip.
Inside that function I create a movie clip object called mainMenuContainer, and an array called menuList.

Then I create movieclip objects using items in the library, and add them to the menuList array. These are the items in the menu. Then I call a second function from inside this function, called arrangeMenu, which just does a little for in loop to give the menu items a y property, adds EventListeners to them, and adds them as children of the mainMenuContainer. Maybe that's a clumsy way of doing things, but that's not the problem.
The problem is that Flash won't run the second function because when it gets to the part where I say

mainMenuContainer.addChild(array[ i]) - space added to avoid italics tag :P

it says:

"1120: Access of undefined property mainMenuContainer."

So I'm thinking, "Okay, what the hell?"
It wasn't necessary to keep that as a separate function, so I solved this by just putting the contents of the arrangeMenu function inside initMainMenu. But that's a temporary solution to a broader problem, because now I've got the same problem with a third function (the function called by the EventListeners) that I can't just lump inside the first. How come I can't refer to objects created by a function from inside other functions? Is it a problem with the order I'm writing them in, or how they're called? I am confused. :|

Referencing Display Objects From An Array
Hi

My Psuedo Code:


Code:
myArray = [MC_01, MC_02, MC_03]

for (arrayLength){
myArray[i].addEventListener(MouseDown)
}

Listener(evt) {
stage.addChild(evt.target) //To bring Clicked MC to top of display list
}

Basically what i'm doing is having my array of MC's jumbled on the stage and when I click I want it to come forward. The way I have made objects move to the top previously is using addChild again on it... and it worked fine. With my code i'm getting

1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.displayisplayObject.

as I try to addChild again. How do I reference the MC properly and make it jump forward properly? I cna't seem to work it out.



Thanks in advance
Jethro

Referencing Objects Created With A Loop
I know there is simple answer here but Im getting tired so here I am.

I am creating buttons for a menu dynamically based on the amount of items in an array. I can create the buttons and labels for them and even make them access their corresponding page that they link to. My question is for the rollover effect, when I roll over I want the text on the button to shift to the right, but because all the buttons were added in a loop I can only reference the last button created.
I think my question is how do I change the instance name of an object? I though .name did it but that doesn't seem to change the actual reference name of an object.

here is what I have:


Code:
for(i=0; i <= numPages - 1; i++){
var menubut:MovieClip = new menuBut();
menubut.name = "b"+(i + 1);
menubut.y = 10 + i * 20;
menubut.pageTitle.text = pages[i];
menubut.addEventListener(MouseEvent.CLICK, changePage);
menubut.addEventListener(MouseEvent.MOUSE_OVER, overMenu);
menubut.addEventListener(MouseEvent.MOUSE_OUT, offMenu);
menucon.addChild(menubut);
}

function overMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x += 3;
}

function offMenu(event:MouseEvent):void{
temp = event.target.name;
menucon[temp].pageTitle.x -= 3;
}
pages is the array and numPages is the length of that array. menucon is the mc that all the menu buttons go into.

Referencing Objects By Name Created At Runtime
Referencing objects by name created at runtime, how do you do it?
Ive remember reading that its tough, but can't seem to find the work around.
I have thumbnail objects (with a thumb class) that are created in a loop and added to a thumbholder class, with the name property added (thumb.name, which when traced is thumb0, thumb1, etc). After runtime I want to interact with the thumbs via mouse events in the thumbholder, e.g. when thumb0 is clicked thumb4 is moved to x=60. But trying to reference thumb0 doesnt work and when I reference thumb it will always return the final thumb, e.g. thumb5.

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

Best Way To Hide On Stage Objects When Other Objects Need To Be Shown?
A typical nubee question..What is the best way to hide objects on sage when a button from navigation is clicked and in response other information or objects need to be shown instead of the one previously on stage?

Help: Stage Objects Get In Front Of Script Objects?
This is getting me mad...

addChild(my_script_object);

I can't see it...

If I try trace(numChildren) I get 10, so then I try addChildAt(my_script_object,9) and still cant' see it.

If I delete all the objects in stage then I finally see it.... If I delete one by one I find my_script_objects gets beneath a bitmap placed by hand by the designer.

Any ideas?

TIA

Best Way To Hide On Stage Objects When Other Objects Need To Be Shown?
A typical nubee question..What is the best way to hide objects on sage when a button from navigation is clicked and in response other information or objects need to be shown instead of the one previously on stage?

Referencing Dynamically Loaded Clips/objects
I've been playing around with building a tile based game after checking out a couple tutorials.. I've established an overhead level with a moveable character and static objects within that environment. My problem is, that I can't seem to properly reference the character or objects (enemy0-7) within a function of the frame. I've tried a variety of possible references (_root.clip.char, etc..) to no avail.. I've attached the FLA (put the map below). Anyone have any ideas?

Thanks,
Shawn

the map is a text file named map.as located in the same folder as the swf.. map works fine.. Here's what's in map.as:

map = [ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,1,1,1,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] ];

// startPosition [x,y]
startPos = [9,14];

// enemys startPositions [x,y]
enemys = [[2,1],[18,2],[9,8],[6,15],[12,18],[10,12],[15,15]];

Simple Problem - Referencing Objects By Variable Name
I have a simple function that dynamically creates text fields. My text field name is referenced by var thisTextField. Problem is, when i try to do things with my text field, actionscript shoots back an error as such:

There is no property with the name 'text'.

How am i supposed to apply properties to my object if my objects name is a variable?



Code:
function showProducts() {

var products:Number = 0;
var thisTextField:String = "product" + products + "_txt";

for (var itemID in _global.rtsData[_global.rtsPos]["products"]) {

this.createTextField(thisTextField,1,25,75,350,50);
trace(thisTextField);
thisTextField.autoSize = true;
product+products+_txt.text = _global.rtsData[_global.rtsPos]["products"][itemID]["products_name"];

products++;

}

_root.products_mc.gotoAndPlay("fadeIn");

}

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?

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

Moving The Stage After Resizing - Or Moving All Objects On The Stage? Heeeelp
Hello! I'm in dire need of help!

I've been forced to resize the stage of my movie but as the stage is expanded to the right and down everything ends up in the wrong place. So I wonder:

Is there any way to move the stage rather than the contents thereon?

or

is there a way to move all the content on all layers and even all scenes simultaneously?

or

is there a way to expand the stage equeally on all sides rather than just right and down?

THANKS ALOT TO WHOEVER COULD HELP ME!


Freddy D, Stockholm, Sweden

Objects Off Stage
I am loading a small movie inside a larger movie. The smaller movie has object off the stage that move across. When I play the small movie by itself shows just the movie stage. But when I load this into the larger movie stage I see all the off stage objects on the smaller movie.

What am I doing wrong?

I Can See Objects Outside The Stage :(
hello,

im testing my flash site and everything looks
pretty good BUT when i resize the window to see what happens....anything thats in the flash file shows up even though it isnt on the stage.
how can i limit the window so it doesnt resize.

i didnt design the site to look good if someone resizes the window. i have very custom edges and if you resize the window the design falls apart.

did i screw up or do flash designers have a work around for this.

also, is it a BAD idea to design this way (framing the edge) because of peoples tendancies to want to resize their browser windows?

Off Stage Objects
I was under the belief that objects off (to the side of the stage) were not visible. When I "test movie" though they are clearly visible. Am I doing something wrong, possibly they need to be masked?


Thanks
Stuart

Objects Off Of Stage
i have a flash movie i made.... when i load it into an empty movie clip in a new flash document, it plays but shows all the items that were off of the stage and on the area around it - when these items are only supposed to be seen moving onto the stage. does this make sense? how do i make it not show any area off of the stage?

thanks a ton in advance
cosmo

MVC And Objects Already On The Stage
So I'm finally really digging into design patterns with AS3 and I'm finally getting the hang of it. I'm currently floating through Adobe's "Advanced ActionScript 3.0 with Design Patterns" by Lott and Patterson.

For the MVC pattern, where exactly does an object fit in that has already been placed on the stage?

The problem comes up because an object on the stage at compile time is immediately instantiated without any real control as to "how" it is instantiated (afaik). The above book's clock example shows adding objects dynamically through an Abstract view, but that view requires arguments, and I don't see how you can pass those arguments at compile time.

Just a bit confused how to combine this together. Check out the clock example here:
http://rightactionscript.com/aas3wdp/

Does MX Allow Objects Outside Stage?
may b its just me but, i remember placing instances outside the stage area and MX doesnt allow it 4 some reason or i'm totally missin somethin??

hog!!~~

Objects Outside Of The Stage
Hello,

As all of us know the objects that are placed outside of the stage are not visible. But is it possible to access and alter these objects. I'm asking that, because of security reasons. I don't want that the user access these objects even if they are not visible. So is it safe to place them just outside the stage.

Any suggestions will be helpful. Thank You.

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