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




Easy Variable Scope Problem



i'm using a slide presentation document, and i have this code attached onto a slide:on (load) { var tmp = 5;}on (reveal) { trace(tmp);}but when i run it, it traces 'undefined'..what am i missing here?



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 10-25-2006, 07:14 PM


View Complete Forum Thread with Replies

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

Easy Variable Scope Problem
'm using a slide presentation document, and i have this code attached onto a slide:

on (load) {
var tmp = 5;
}
on (reveal) {
trace(tmp);
}

but when i run it, it traces 'undefined'..
what am i missing here?

Variable Scope - Dynamically Created Variable Not Working
Hi all,

For a movieclip obj, I created a dynamic variable and in the onLoadInit handler this variable is not accessible.

This is my code:
--------
var imagesList:Array = new Array("flagGreen.gif", "flagRed.gif");
var path = "images/";

var myMc:MovieClip
= _root.createEmptyMovieClip("myMc", _root.getNextHighestDepth());
myMc.url = path+imagesList[0];

var loader = new Object();
loader.onLoadInit = function(targetMc){
trace( "url1:"+targetMc.url);
trace( "url2:"+_root.myMc.url);
trace( "width:"+targetMc._width);
trace( "height"+targetMc._height);
}

var mcLoaderObj:MovieClipLoader = new MovieClipLoader();
mcLoaderObj.addListener(loader);
mcLoaderObj.loadClip(myMc.url, myMc);

-----------

Image is getting loaded. When myMc.url is passed as a param to loadClip, it is working, but inside onLoadInit it is printed as undefined.

Help will be appreciated. Thanks in advance.

- Kiran

Variable Scope
If I declare a variable in a movie clip, can I access it in another movie clip? If so, how?

Ya-Tin

Variable Scope
Hello --
I hope someone can help me -- I seem to be losing the value in an some variables I have:
I am new to Flash and am trying to make a simple (or so I thought!) movie with a text box displaying a list of current events, one by one. I want to store the events in an array, and have the first one display in a dynamic text box for a few seconds (maybe scroll across the screen), then display the next array item (next current event), then the next, and so on.
I have a movie with 2 layers: Actions and Display. My code so far is in the first frame of the actions layer.
The Display layer contains a dynamic text box set to the variable "newsitem" - this is where I want to display my events.
I have a text file (news.txt) containing the events, each event separated by a carat ("^").
Contents of text file:
txtmsg=October 20-21, 2002 FIN User Conference, Van Nuys, CA^November 2-3, 2002 Vancouver Tech Conference, Vancouver, BC

I load the text file into a Flash variable (txtmsg) (this part works fine). I then use the split function to separate out each event into its own array item. Here's my code from frame 1 of the actions layer:
loadVariablesNum ("news.txt", 0, "POST");
mycounter = 0;
newsarray = txtmsg.split('^');
newsitem=newsarray[mycounter];

This works fine (meaning when I test the movie, and choose Debug - List Variables, each event is listed as an array item.)

BUT when I go on to the next step, and add 20 frames to each layer(where the first newsarray item would display in the text box newsitem), and add this piece of code in frame 20 of the actions layer to bring in the next array item and display it in the text box newsitem:
mycounter++;
newsitem=newsarray[mycounter];
gotoAndPlay (2);

When I add this code, and test the movie, the variable newsarray is "undefined", as is newsitem. The variable "txtmsg" which contains the unsplit text straight from the text file, still contains its original value.


I don't know if somehow the variable containing the array is going out of scope, or what!
Can someone please tell me what I'm doing wrong?

Thanks!
Kathy

Variable Scope
Hello,
nice easy one for ya
I have a function on the main time line that basicly creates and array
All I wan't do is access that array from within another function - should be easy but cant remember for the life of me how to do it????

I'll include a bit of an example for clarity -

//function 1

function makeArray(){
dest = -10 + random(780);
speed = 10+ random(5);
direc = random(2)
return man = [dest, speed, direc];
}

//function 2
function move{
man[1] yada yada yada
}
You get the point
any help happly recieved

(sorry about spelling was in bit of a rush)

Variable Scope
I need to access a variable that is declared in the main time line from inside 2 movie clips, ie. the variable knightshealth is declared in the main timeline but I need to access it from the movie clip knight.knightshealth. How would I do this?

Thanks

Variable Scope
How comes when I run the script below, the variable “tip” is shown as “undefined” even though I did not declare it as being local to the function with the “var” keyword & so it should show up in timeline scripts?
code: net=function(){
tip=10;
}
trace(tip);

In other words if Flash treats variables inside functions as local without the use of “var” why bother using it to declare a variable local only to that function?

Variable Scope
I am having problems with variable scope.

Variables in different functions are clobbering eachother, especially for loops. Is there a way to scope a variable to a function?

Thank you.

functionA() would be called only once in the following example

functionA(){
for(x=0; x<100;x++){
functionB(){
for(x=0;x<100;x++){
null;
}
}
}
}

Variable Scope?
This seems so simple but I keep getting an error.

On the main (root) timeline I have
var theFrame:String = "whatever";


In a movie clip instance sitting on the stage I have:
trace (root.theFrame);

Shouldn't that output "whatever"?

But instead it gives an error.
1119: Access of possibly undefined property theFrame through a reference with static type flash.displayisplayObjectContainer.

Variable Scope
i have a question about variable scope in AS3 - if my understanding is correct, a variable defined within a function will not assign a value to a global? but if i'm passing variables to a constructor function like the following, how do define a global variable defined in the class body


ActionScript Code:
var myclock1:ObjectTimer = new ObjectTimer(1 , 4, 'nut1.png', 124, 41, 'ExpandAPrimary', left);

the final arguement is left, and its grabbed by the constructor function of the ObjectTimer class like so:


ActionScript Code:
public function ObjectTimer(_myInTime:Number, _myOutTime:Number, _imageUrl:String,_x:Number,_y:Number,_transition:String, _direction:String) {


how do i get _direction:String to be assigned to a global variable which is accessable by other functions

Variable Scope..
I`ve created an event handler on `blip` movieclip as follows. Could someone explain how to access the variables `posArray` and `thisPos` within the handler?

Code on main timeline:


Code:
var posx:Number;
var posy:Number;
var posz:Number;
var posArray:Array = new Array();
var thisPos:Number=0;

var anchor1:Vector3D=new Vector3D(10,20,40);
var anchor2:Vector3D=new Vector3D(330,450,500);
var control1:Vector3D=new Vector3D(90,110,100);
var control2:Vector3D=new Vector3D(230,350,400);

for (var i:Number = 0; i<=10; i++) {
var u:Number=i/10;

posx = Math.pow(u,3)*(anchor2.x+3*(control1.x-control2.x)-anchor1.x)
+3*Math.pow(u,2)*(anchor1.x-2*control1.x+control2.x)
+3*u*(control1.x-anchor1.x)+anchor1.x;
posy = Math.pow(u,3)*(anchor2.y+3*(control1.y-control2.y)-anchor1.y)
+3*Math.pow(u,2)*(anchor1.y-2*control1.y+control2.y)
+3*u*(control1.y-anchor1.y)+anchor1.y;
posz = Math.pow(u,3)*(anchor2.z+3*(control1.z-control2.z)-anchor1.z)
+3*Math.pow(u,2)*(anchor1.z-2*control1.z+control2.z)
+3*u*(control1.z-anchor1.z)+anchor1.z;

posArray[i]=[posx,posy,posz];
}

blip.addEventListener(Event.ENTER_FRAME, blipEnterFrame);

function blipEnterFrame(e:Event) {
e.target.x=posArray[thisPos][0];
e.target.y=posArray[thisPos][1];
e.target.z=posArray[thisPos][2];
thisPos++;
}

Scope Of A Variable?
Hi every1! I got this code:

Code:
cycle for 1<i<10:
_root["containter"+i].onRelease = function () {
_root.play();
_root.blackout.gotoAndPlay(1);
_root.media2load = "works/" + myVars["media"+i];
}
end of cycle
So, when I check then "_root.media2load" after I click on the container1 (for example) it says "undefined". So, I guess the cycle doesn't go into this function and work it out only when the flash is playing and when I click on that container. But then the variable "i" has the its last value = 10.
What should I do?

Scope Of A Variable?
I seem to be having difficulty in using the contents of a variable whan i receive the data from the database the script places the contents in a variable called myText1

This I need to access outside the function.

Any ideas?

This is part of the script below.
//----------------------------------------------------------------------------------------

mypath = "http://192.168.0.100/fedpest/pestReports/"
mypath1 =mypath + "exterior.php";

var sendData = new LoadVars();
var recData = new LoadVars();
recData.onLoad = getResponse;


sendData.id_num = 1;

sendData.sendAndLoad(mypath1, recData, "post");


function getResponse(result){

myText1=this["mytext"];

};


AreasSituationsText.text=myText1;
//--------------------------------------------------------------------------------------

Variable Scope
ok I have a class wich has this

public static var XmlToArray:Array = new Array();

now when i trace this from inside a class's function

public function trace() {

trace(XmlToArray[i].url);

it traces. But when I am trying to trace it from inside a function that a define as a listener :

tmpTimer.addEventListener(TimerEvent.TIMER, function tmp() {
trace(XmlToArray[i].url);
}

traces null so I guess the tmp is not a member of my class and can't see the array. when can I do to get access to the array.

Variable Scope
I have a map of the world. Each country is a movieclip with a class of "Country" linked to it. Now in the timeline I have a variable for a color. How can I access that variable which is on the timeline from the Country class?

Variable Scope?
Stuck on this, seems easy but my brain just isn't working.


Code:
public class application extends MovieClip
{
var externalXML:XML;
private var array:Array;

public function startApp()
{
array = new Array();
getXML("images.xml");
moveSprite(array);
}

/*
* public function getXML()
* String: xml - external XML file
*
*/
public function getXML(xml:String):void
{
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(xml);
loader.load(request);
loader.addEventListener(Event.COMPLETE, onComplete);

// is called on completion of obtaining XML file
function onComplete(event:Event):void
{
var loader:URLLoader = event.target as URLLoader;
if (loader != null)
{
externalXML = new XML(loader.data);
parseXML(externalXML);
}
else
{
trace("loader is not a URLLoader!");
}

}
}

/*
* public function parseXML()
* XML object: xmldata - the incoming xml feed
*
*/
public function parseXML(xmldata:XML):void
{
var sprite:Sprite = new Sprite();
var image:Loader = new Loader();
image.load(new URLRequest(xmldata.image[0].file[0]));
addChild(sprite);
sprite.addChild(image);
array.push(sprite);
}
public function moveSprite(s:Array)
{
s[0].x = 100;
}
}
I get my image to display fine, but I can't access the sprite inside the array anywhere else but in the parseXML function, which is useless. Why can't I send the array to this moveSprite function and move it around the screen? I get Error #1010: A term is undefined and has no properties. I don't get it atm.

Variable Scope
I took the following code snippet from:
http://www.tutorialized.com/tutorial/Variable-Scope/4939
CODE//I removed the explanations from this code
_root.createEmptyMovieClip("test",1);
i=5;
test.onEnterFrame=function()
{
  trace (_root.i);
  trace (i);
  trace (this.i);
}

_root.i // returns 5
i // returns 5
this.i // returns undefined

Variable Scope Question
I'm trying to create a system similar to a weather map, where points of interest are loaded from a database and displayed as icons on a map in real time. When I click on an icon, a window pops up with more detailed information about that point, but I'm having problems getting variables from one MC to the other. Specifically, the detailed information window shows the same information for any icon, which is the information of the very last one loaded. Here's the code:

in the main movie,

for (z=1; z<=count; z++) {
clipcount++;
duplicateMovieClip ("_root.TargetMarker", "t"+clipcount, clipcount+100);
x = eval("tx"+z);
y = eval("ty"+z);
dx = (x-TLLong)*500/(BRLong-TLLong);
dy = (y-TLLat)*400/(BRLat-TLLat);
r = eval("ber"+z);
a = eval("alt"+z);
v = eval("vel"+z);
c = eval("cls"+z);
setProperty ("t"+clipcount, _x, dx);
setProperty ("t"+clipcount, _y, dy);
setProperty ("t"+clipcount, _rotation, r);
tellTarget ("t"+clipcount) {
x = _root.x;
y = _root.y;
r = _root.r;
a = _root.a;
v = _root.v;
c = _root.c;
}
}

So this part should take the new data, which is like ber1=100 ber2=430 alt1=234 alt2=254 .... for all the variables there, and creates a new movie clip with the icon, positions it on the map, and then sends the variables x, y, r, a, v, and c to it.

This clip should in turn pass the variables to the detail screen movie clip when it's pressed. When that movie clip is released, the following code is executed:

on (release) {
duplicateMovieClip ("_root.TargetInfo", "TargetInfo2", 9999);
setProperty ("_root.TargetInfo2", _x, "250");
setProperty ("_root.TargetInfo2", _y, "200");
tellTarget ("_root.TargetInfo2") {
x = _parent.x;
y = _parent.y;
r = _parent.r;
a = _parent.a;
v = _parent.v;
c = _parent.c;
}
}

This appears to work, but I presume it's always sending _root's current variables, rather than _targetmarkerxx's copy, which is what I want to send.

How can I correct this, or is there an easier way to go about setting this up? Thanks.

Andrew Fabian

Scenes And Variable Scope
Hey all,
I'd just like to clarify something to be sure of what I am doing.

Does Flash 5 player treat a movie with multiple scenes exactly the same as one with one scene?

Basicly, my question comes down to the variable scope.
If I set a global variable in scene 1, will it be avalible in scene 14?

Also, is this behaviour the same in flash 4?

Thanks in advance!

Variable Scope Throughout Scenes
I have an existing flash program and it contains several scenes. I now need to add shopping cart functionality and need to know how the variable scope will work between scenes. Do i have to place a shopping cart movie in each scene to keep track of what has been ordered or can i load a scene in the background that the user will not see that can keep track of items orders and such?

Variable Scope Question
Hello,

I have a question concerning variable scope because of something that happened when I made some changes tonight.

I have three variables that are defined globally:

cardx, cardy, and cardNum . . .

they are not initialized to anything, instead they are initialized ( and incremented accordingly ) during an onPress event by a button.

Later, they are reset to new amounts. Before I was using a button - everything worked just fine. I changed the button into a movie clip. When the user presses the movie clip it should have some effect on the variables, but it is not - it does not do anything to the variables?

Can anyone lend some insight as to why?

Jim

Global Variable Scope
I am designing a site consisting of several swf-files, and I am dependant on reaching global variables from the swf files which I load into the "Master" swf file.

There are not many variables so i suppose I could send them using a GET argument while I load the swf-file, but isn't that unnecessary?

-Shouldn't global variables be visible to all content loaded into a swf-master-file?

Help appreciated.

MAB71

[ActionScript 2.0] Variable Scope
I have a method and a constructor in my class.

The constructor calls a variable that is in the method. The method computes something and turns back a variable name 'addthis', making it either 2 or 3 from an if / else statement.

OK - my question is, the constructor makes it undefined, although I define the variable in the method below it.

Can anyone tell me what I need to do? Do I need to make the method have a return value and then do something? Very lost... thanks!

If I wanted to, I could eliminate the function and put the if / else statement in the constructor, but I have a dozen functions that all compute and then return to the constructor.

Thanks.

Variable Scope In Class (AS 2.0)
I have a movie clip attached at runtime. I have a class linked to the movie clip. The movie clip is attached at root. All this works but check out how I am accessing the variables in the functions (ie: _parent.alphaon and _parent.alphaoff) Surely there must be a better way. Thanks for your comments.


Code:
//Constructor Function
function Screen() {
id = id;
path = _root["Screen"+id];
alphaon = 80;
alphaoff = 100;
setupdrag();
}

//Set Up Drag
function setupdrag() {

path.dragger.onPress = function() {
_parent.startDrag();
_parent._alpha = _parent.alphaon;
_parent.swapDepths(myDepth);
}

path.dragger.onRelease = function() {
stopDrag();
_parent._alpha = _parent.alphaoff;
}
}
}

Possible Variable Scope Problem?
I am new to flashkit, so hello to all. I am using Flash MX (6.0). I am having problems accessing an array I built from a read in CSV file. It shows up in the debugger fine, but any trace() commands on the array come up undefined. The idea is to populate a set of textboxes with values in the array. My code is below. Any ideas? Thanks.

code:
// Initialize variables and constants
var _fileload = new LoadVars();
var full_array = new Array();
var temp1_array = new Array();
var temp2_array = new Array();
var DIR = "pix/";

// Start the data loading
_fileload.load("csv.txt");

// Assign text
Title_txt.text = full_array[0,0]; //Get nothing from here

// Write array cell
trace(full_array[0][0]); //Comes up undefined

// Functions
_fileload.onData = function(txtfile)
{
temp1_array = txtfile.split('
');
for (var i = 0; i < temp1_array.length-1; i++)
{
temp2_array = temp1_array[i].split(',');
full_array[i] = temp2_array;

}
};

Variable Scope Question
I've got one swf where some variables are set based on user input. I need to transfer the values of those variables to a couple of additional swfs. How do I do that? I tried using global variables and unless I'm putting them in the wrong place, that doesn't work. I've read some about loadVars and am thinking that must be the way to do it but that's not a class I've ever used. Am I on the right track thinking that loadVars is the way to go? If so, could some one get me started or give me some tips? It looks a little overwhelming.

Thanks.

Variable Scope Problem
I'm using the following code to scale a movieclip when a different movieclip is rolled over. The buttons are the names in the array and the ones that are supposed to scaled are "arrayvaluePic". The problem I'm having is that tempImg isn't being set properly. Every single button gets set to the very last array value. I can't figure it out, if anyone can be of help, it would be greatly appriciated.



Code:
teamMembers = new Array(
"andy",
"greg",
"matt",
"ben",
"aaron",
"chad",
"scott",
"dave",
"todd",
"mark",
"joy",
"gail",
"andrew",
"lucinda",
"john",
"susan",
"davet"
);

function applyScales() {
var teamCount = teamMembers.length;
for (i = 0; i < teamCount; i++) {
var temp = this[teamMembers[i]];
var tempImg = this[teamMembers[i] + "Pic"];

// mouse over functions
temp.onRollOver = function() {
tempImg.scaleTo(100, 1);
trace(tempImg);
};

// mouse out functions
temp.onRollOut = function() {
tempImg.scaleTo(33.3, 1);
};

//write out array value for testing
//trace(tempImg);
//trace(temp);
}
}

applyScales();

Variable Scope Issue
Hi all,
I'm having difficulties calling a variable outside of a function.
This is what i have:

Code:
//set var outside function
var totalHolderHeight:Number = 0;

//handle server response
this.getContacts_Result = function(result)
{
if(result)
{
// the code below needs attention, specifically in relation to session handling, global vars etc.
if (query_type == "detailed"){
title = result[0];
login_details = result[1];
}
company_details = result[2];
contact_user_details = result[3];

if (result['status'] == "null")
trace("EMPTY");
//if (contact_user_details['pm_user_id'].length == "")
//trace("EMPTY");

var styles = new TextField.StyleSheet();

styles.load("include/css/styles.css");
styles.onLoad = function(ok) {

if (ok) {
// display style names
this.getStyleNames();

} else {
trace("Error loading CSS file.");
}

page_title.styleSheet = styles;
page_title.text = "<p class='three'>" + title['admin_contacts_page'] + "</p>";
login_name.styleSheet = styles;
login_name.text = "<p class='login_txt'>Logged in as " + login_details['pm_full_name'] + "</p>";
company_detail_mc.company_name.styleSheet = styles;
company_detail_mc.company_name.text = "<p class='three'>" + company_details['pm_company_name'] + "</p>";

};

var totalHolderHeight = 0;

for (var j = 0; j<contact_user_details['pm_user_id'].length; j++) {

createEmptyMovieClip("holder", this.getNextHighestDepth());

contactDetails_mc = holder.attachMovie("dynamic_id", "newClip_mc"+j, j);

contactDetails_mc.user_id = contact_user_details['pm_user_id'][j]
contactDetails_mc._x = 0
contactDetails_mc._y = j*90

contactDetails_mc.full_name_txt.styleSheet = styles;
contactDetails_mc.full_name_txt.text = "<p class='three'>" + contact_user_details['pm_first_name'][j] + " " + contact_user_details['pm_last_name'][j] + "</p>";
contactDetails_mc.email_txt.styleSheet = styles;
contactDetails_mc.email_txt.text = "<p class='one'><a href='mailto:"+contact_user_details['pm_email'][j]+"'>"+contact_user_details['pm_email'][j]+"</a></p>";

totalHolderHeight += contactDetails_mc._height+14;

}
return totalHolderHeight;

} // end result
}

//Manage possible errors
this.getContacts_Error = function(status){

trace("Error")
}

_global.totalHolderHeight = this.getContacts_Result();
trace(totalHolderHeight);
When i trace(totalHolderHeight) i get "0". Anu ideas as to how i should be calling the function to give me the updated value?

Cheers

Variable Scope Problem? Or Something Else?
So i'm at an official loss. I'm trying to use some of the XML loading functions in a seperate class, and it's refusing to work properly.

It's such a specific problem that I'm not even sure what to search for..

Here's what I've got:
First, the class.
class testClass
{
var xmlTableName:String = "";
var xmlTable:XML;
public function testClass(xmlTableName:String)
{
trace("constructor");
xmlTable = new XML();
xmlTable.ignoreWhite = true;
xmlTable.onLoad = readXML;
xmlTable.load(xmlTableName);
trace("loading "+xmlTable+" with "+xmlTableName);
}
public function readXML(loaded)
{
if(loaded)
{
trace("loaded");
}
else
{
trace("kaput");
}
trace("xml table is "+xmlTable);
}
}
This is called with
var testThing:testClass;
init();
function init()
{
testClass = new testClass("skills.xml");
}
My trace output is:loading with skills.xml
loaded
xml table is undefinedSo what's happening is that even though xmlTable is declared in the class declaration, and newed up in the constructor, and the xml file says it loaded properly, it returns back into the "Loaded" call with an undefined XML object.

Any ideas? I assume this is a problem with variable scope, or a misuse of something related to that...

I'm officially at a loss..

Thanks,
-Dan

Variable Scope In Class
Hello,
I'm just getting started with OOP and writing classes. I've come across a problem. where Variables declared in the class are lost somewhere in the scope of things...

The static var X is'nt available to the method onBtn().. why? I'm probably missing something simple...


ActionScript Code:
class TestVars
{
    // reference to timeline
    var root:MovieClip; 
    // VARS
    var a:Number = 0;
    static var X:Number = 5;

    //constructor
    function TestVars(root:MovieClip)
    {
        this.root = root;
        init();
    }   
    // set up
    function init()
    {
        //  SET UP BUTTON 
        root.btnNext.scope = this;
        root.btnNext.onRelease = function()
        {
            this.scope.onBtn();
        }
       
        // START UP
        setVar(a);
    }
    //Set new variable 
    function setVar(t:Number)
    {
        a = t;
        trace('a: '+ a +' :'+ typeof(a))
    }   
           
       
    function onBtn()
    {
        trace('onBtn called: '+a+' + '+X+' = '+a+X) // TRACES: 0 + undefined = 0undefined   
        setVar(a + X);
    }
}

any help apreciated.
thanks

.henkedo

Variable Referencing/Scope
Sorry for the newbie question, but my books are not doing a superb job of explanation...

I have a flash document that has multiple scenes, and I need to have a couple of variables that I can reference and/or change throughout the document. Can anyone tell me the syntax to declare and reference these kinds of variables?


For example in Scene 1, named Login, I have:

var bLoggedIn:Boolean;
....
bLoggedIn = True;



Now, I need to use that variable in an if test in Scene 2, named SavedReports:

if(bLoggedIn == True){
....
}

I have tried the following with a result of undefined:
_root.bLoggedIn
bLoggedIn
_root.Login.bLoggedIn


Thanks a bunch for the help!!!

Class Variable Scope
I am trying to call an object's method in an event handler. It seems that the object was never defined.


Code:
// Main.as

class Main
{
var mc:MovieClip = null;
var b:Body = null;

static function main()
{
trace("main");

var m = new Main();
}

function Main()
{
trace("Main::Main");

this.mc = _root.createEmptyMovieClip("z00", 1);
this.b = new Body();

this.mc.onEnterFrame = this.onFrame;
}

function onFrame()
{
trace("Main::onFrame");
trace(this.b);
}
}

Code:
// Body.as

class Body
{
function Body()
{
trace("Body::Body");
}

function draw(mc:MovieClip)
{
trace("Body::draw");
}
}

Code:
// Output
main
Main::Main
Body::Body
Main::onFrame
undefined
Main::onFrame
undefined
Main::onFrame
undefined
...
Strangely, if I trace(this.mc) in Main::onFrame it is undefined also. The object that is generating the event is undefined?! I am going mad. Someone please help!

Variable Scope Question
I have a flash variable scope question, and I'm not sure how to reference the variable.

In my text file is &myColor=blue

The three movie instances don’t want to change color based on the loaded text variable. Perhaps you can shed some light.

I’m trying to fix this so designers have options for color, but are set with particular brand colors.


Code:

#include "lmc_tween.as"

var fadeTime:Number = 2;

loadText = new LoadVars();
loadText.load("assets/description.txt");
loadText.onLoad = function() {
title_txt.text = this.title;
subtitle_txt.text = this.subtitle;
description_txt.text = this.description;
sectionOne_txt.text = this.sectionOne;
sectionTwo_txt.text = this.sectionTwo;
sectionThree_txt.text = this.sectionThree;
footer_txt.text = this.footer;
_global.my_color = this.myColor;
middle_bg._alpha = 20;
trace(my_color);
if (my_color == "teal") {
theColor == "0x156570";
} else if (my_color == "blue") {
theColor == "0x44697D";
} else if (my_color == "green") {
theColor == "0x496C60";
} else if (my_color == "grey") {
theColor == "0x666666";
}
top_bg.colorTo(theColor, fadeTime, easeInOut);
middle_bg.colorTo(theColor, fadeTime, easeInOut);
bottom_bg.colorTo(theColor, fadeTime, easeInOut);
};

Variable Scope Issues..
I just cant seem to get this code stuff...

function cycleLoad - works, it adds 6 buttons on the stage evenly around a circle..

function over, function out - works, when onRollOver, onRollOut the buttons zoom in and out

Im having a hard time with the function release, function unrelease... I want the user to click on any of the 6 buttons, remeber there location, and onced click on, the button zooms up, and the rest of the 5 buttons fade to zero, once the user clicks on a back button, the large image will zoom back to the cycle, the 5 other buttons will fade back in, then the user can click on any of the 6 buttons again...


heres my code

ActionScript Code:
import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.*;

var numOfItems:Number = menuIconsArray.length;
var radiusX:Number = 180;               //width radius of cycle for the animated icons
var radiusY:Number = 150;               //height radius of cycle for the animated icons
var centerX:Number = 250;               //X center of cycle
var centerY:Number = 210;               //Y center of cycle
var cycleRotate:Number = 300.03;
var arrowCenterX:Number = 110;
var arrowCenterY:Number = 80;
var arrowRadiusX:Number = 0;
var arrowRadiusY:Number = 0;

var menuIconsArray:Array = new Array("healthySkin", "environMoist", "lowerSkin", "drySkin", "waterInfusion", "healthyCellular");


function cycleLoad() {
    for (var i:Number = 0; i < menuIconsArray.length; i++) {
        var emptyClip:MovieClip = _level0.createEmptyMovieClip("container_mc_" + i, _level0.getNextHighestDepth());
        var theMovie:MovieClip = emptyClip.attachMovie(menuIconsArray[i] , "item" + i, emptyClip.getNextHighestDepth());
        //trace("attaching " + menuIconsArray[i] + " to" + " cont" + emptyClip);
        //trace("poo " + theMovie);
        theMovie.angle = i * ((Math.PI * 2)/menuIconsArray.length) + cycleRotate;
        theMovie.onEnterFrame = placement;
        theMovie.onRollOver = over;
        theMovie.onRollOut = out;
        theMovie.onRelease = released;
    }
}

cycleLoad();

var arrowMC:MovieClip = _level0.attachMovie("arrows", "arrows", 0);
arrowMC.onEnterFrame = placement;
arrowMC._x = arrowCenterX;
arrowMC._y = arrowCenterY;


function over(theMovie:MovieClip) {                         if (theMovie = this) {              var tw:Tween = new Tween (theMovie,"_xscale",Strong.easeOut,this._xscale,110,0.3,true);
        var tw2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,this._yscale,110,0.3,true);
        }
}

function out(theMovie:MovieClip) {
        if (theMovie = this) {              var tw:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,this._xscale,100,0.3,true);        var tw2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,this._yscale,100,0.3,true);
        }
}


function released(theMovie:MovieClip) {
        var theMovie:MovieClip = _level0[menuIconsArray[i]];        var arrowMC:MovieClip = arrowMC;               
        arrowMC.xPos = arrowMC._x;
        arrowMC.yPos = arrowMC._y;
        arrowMC.theScale = arrowMC._xscale;
       
        delete theMovie.onRollOver;
        delete theMovie.onRollOut; 
        delete theMovie.onRelease;
        delete theMovie.onEnterFrame;
               
        theMovie.xPos = this._x;                        theMovie.yPos = this._y;                        theMovie.theScale = this._xscale;
               
        if (this != this) { //I NEED HELP HERE!!!!!!!!
                   
            var theMovie:Tween = new Tween(this,"_xscale",Strong.easeOut,this._xscale,50,0.5,true);
            var theMovie2:Tween = new Tween(this,"_yscale",Strong.easeOut,this._yscale,50,0.5,true);
            var theMovie3:Tween = new Tween(this,"_alpha",Strong.easeOut,75,100,0.5,true);
            var arrowMC:Tween = new Tween(arrowMC,"_alpha",Strong.easeOut,100,0,0.5,true);
        } else {                           
            var theMovie:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,this._xscale,350,1,true);
            var theMovie2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,this._yscale,350,1,true);
        }
}

function unReleased() {
    delete this.onRelease;
   
        var theMovie:MovieClip = _level0[menuIconsArray[i]];           
        if (this != this) {  //I NEED HELP HERE!!

            var theMovie:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,0,theMovie.theScale,0.5,true);   var theMovie2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,0,theMovie.theScale,0.5,true);
            var theMovie3:Tween = new Tween(theMovie,"_alpha",Strong.easeOut,75,100,1,true);
            var theMovie4:Tween = new Tween(theMovie,"_x",Strong.easeOut,theMovie._x,theMovie.xPos,0.1,true);         var theMovie5:Tween = new Tween(theMovie,"_y",Strong.easeOut,theMovie._y,theMovie.yPos,0.1,true);
            var arrowMC:Tween = new Tween(arrowMC,"_alpha",Strong.easeOut,0,100,1,true);
           
        } else {                                   
            var theMovie:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,350,theMovie.theScale-20,0.5,true);            var theMovie2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,350,theMovie.theScale-20,0.5,true);
            var theMovie3:Tween = new Tween(theMovie,"_x",Strong.easeOut,theMovie._x,theMovie.xPos,0.5,true);         var theMovie4:Tween = new Tween(theMovie,"_y",Strong.easeOut,theMovie._y,theMovie.yPos,0.5,true);   
            theMovie.onMotionStopped = function() {
                    var theMovie:MovieClip = _level0[menuIconsArray[i]];
        theMovie.onRollOver = Delegate.create(theMovie,over);
        theMovie.onRollOut = Delegate.create(theMovie,out);       theMovie.onRelease = Delegate.create(theMovie,released);
        theMovie.onEnterFrame = placement;
        }
    }
}


function placement() {
    this._x = Math.cos(this.angle) * radiusX + centerX;
    this._y = Math.sin(this.angle) * radiusY + centerY;
}

Variable Scope Issue?
I'm having what I think is a variable scope issue, but I'm not sure why.

In my class definition, I'm defining a number of variables, including on called "articleArray", like so:


Code:
public class ImageLoader extends Sprite {
// variables
var slideNum:Number = 0;
var imgLoader:Loader = new Loader();
var slideTimer:Timer = new Timer(5000); //runs every 5 seconds
var articleArray:Array;
var myImage:String;
And then in the constructor, I am populating that variable with an array that gets passed in to the constructor. At this point, I can access articleArray and all of its component parts.


Code:
public function ImageLoader(articleArray) {

articleArray = articleArray;
loadNextImage(slideNum);

}
However, the next step is for me to call loadNextImage. As I understand it, I should be able to freely access articleArray from within this function because the var is inititialized in the class definition, outside of any function (even the constructor). However, when I try to access it from inside the loadNextImage() function, it returns as null. Here is that function code:


Code:
public function loadNextImage(slideNum:Number) {
trace(articleArray); //this is what returns null
myImage = articleArray[slideNum].imageBig
imgLoader.load(new URLRequest(myImage));
addChild(imgLoader);
trace (imgLoader.name);
imgLoader.x = 0 ;
imgLoader.y = 0;
}

OOP Problem....variable Scope With AS3
Hi guys

How can I get use a variable called from a moviclip's timeline inside my main timeline?

I have got a Document Class, so I declare a private variable called "flag".

package{
...
public class MotionMove01 extends MovieClip{
public var flag:String = "one"; <--this one even is public

public function MotionMove01(){
init();
}
...
public function getFlag():String{
return flag;
}
}

The blue code is a classical "get" function in OOP...I have got moviclips in my main timeline that they used that flag variable and everything is ok, But when I have tried to use that variable from within a movievlip...it doesn't work.....Flash says to me something like this: "Access of undefined property called flag"
Ok, I thought about used my get function with an object of this class....and it doesn't work......so:

How can I get use a variable called from a moviclip's timeline inside my main timeline? the varible is declarated inside the Document Class and I want to use this one inside anyone movieclip's timeline.

Thank you guys for read this one

Variable Scope Question...
Hi guys,

I have a variable scope problem with this code:

Code:
var XML4:XML = new XML();
var pathtologo = new String();
XML4.ignoreWhite = true;
XML4.onLoad = function(success) {
if(success){
pathtologo = XML4.firstChild.childNodes[3];
trace("(1) Path to logo is: "+pathtologo);
}
}
conXML4.load("common.xml");

trace("(2) Path to logo is: "+pathtologo);
trace on (2) gives no value and I would like to somehow get the value there instead of being forced to use only method (1) to generate a value.

How should I do that?

Variable Access Scope
It's been a long while since I'd touched Actionscript, since all this while I'd been fiddling with C# and C++. So coming back to the question of variable scope in Actionscript, I'm a bit at a loss.

When I create an object within the scope of a class method, then proceed to return that object and store it somewhere else, does that object go out of scope and marked for garbage collection?


ActionScript Code:
package{
public class Example
{
   private var storage:Object;
   
   public function Example():void{
      // will the object that "storage" is currently referencing ever be deleted?
      storage = callA();
   }

   public function callA():Object{
      return new Object();
   }
}
}

In C++ it turns null instantly. In C#, well, I can't remember. But I'm quite certain in Actionscript, as long as you have a reference to something, it won't get marked for GC. But then, what use is the variable scope then? When would it ever come into place?

Variable Scope Issue
I have a load variables script that loads the variables a1-a15 from text files a1.txt-a15.txt. I have 16 layers that need access to these variables one layer is /game and the others are sublayers /game/board/one - /game/board/fifteen.

My problem is that before I send these variables to the layers, I need to run them through a function. normally I would run the function on each variable right after they are loaded but I need to average all the variables in the _root layer.

so now that everyone trying to help me is confused I will post the code....

================================================
================================================

This is the current working code sending the variables directly to the layers

================================================
================================================

PHP Code:



loadVariables("./dll files/q3/a1.dll", "/game/board/one");
loadVariables("./dll files/q3/a2.dll", "/game/board/two");
loadVariables("./dll files/q3/a3.dll", "/game/board/three");
loadVariables("./dll files/q3/a4.dll", "/game/board/four");
loadVariables("./dll files/q3/a5.dll", "/game/board/five");
loadVariables("./dll files/q3/a6.dll", "/game/board/six");
loadVariables("./dll files/q3/a7.dll", "/game/board/seven");
loadVariables("./dll files/q3/a8.dll", "/game/board/eight");
loadVariables("./dll files/q3/a9.dll", "/game/board/nine");
loadVariables("./dll files/q3/a10.dll", "/game/board/ten");
loadVariables("./dll files/q3/a11.dll", "/game/board/eleven");
loadVariables("./dll files/q3/a12.dll", "/game/board/twelve");
loadVariables("./dll files/q3/a13.dll", "/game/board/thirteen");
loadVariables("./dll files/q3/a14.dll", "/game/board/fourteen");
loadVariables("./dll files/q3/a15.dll", "/game/board/fifteen");
loadVariables("./dll files/q3/a1.dll", "/game");
loadVariables("./dll files/q3/a2.dll", "/game");
loadVariables("./dll files/q3/a3.dll", "/game");
loadVariables("./dll files/q3/a4.dll", "/game");
loadVariables("./dll files/q3/a5.dll", "/game");
loadVariables("./dll files/q3/a6.dll", "/game");
loadVariables("./dll files/q3/a7.dll", "/game");
loadVariables("./dll files/q3/a8.dll", "/game");
loadVariables("./dll files/q3/a9.dll", "/game");
loadVariables("./dll files/q3/a10.dll", "/game");
loadVariables("./dll files/q3/a11.dll", "/game");
loadVariables("./dll files/q3/a12.dll", "/game");
loadVariables("./dll files/q3/a13.dll", "/game");
loadVariables("./dll files/q3/a14.dll", "/game");
loadVariables("./dll files/q3/a15.dll", "/game");

tellTarget ("game/board/one") {
    gotoAndStop(1);
}
tellTarget ("game/board/two") {
    gotoAndStop(1);
}
tellTarget ("game/board/three") {
    gotoAndStop(1);
}
tellTarget ("game/board/four") {
    gotoAndStop(1);
}
tellTarget ("game/board/five") {
    gotoAndStop(1);
}
tellTarget ("game/board/six") {
    gotoAndStop(1);
}
tellTarget ("game/board/seven") {
    gotoAndStop(1);
}
tellTarget ("game/board/eight") {
    gotoAndStop(1);
}
tellTarget ("game/board/nine") {
    gotoAndStop(1);
}
tellTarget ("game/board/ten") {
    gotoAndStop(1);
}
tellTarget ("game/board/eleven") {
    gotoAndStop(1);
}
tellTarget ("game/board/twelve") {
    gotoAndStop(1);
}
tellTarget ("game/board/thirteen") {
    gotoAndStop(1);
}
tellTarget ("game/board/fourteen") {
    gotoAndStop(1);
}
tellTarget ("game/board/fifteen") {
    gotoAndStop(1);





================================================
================================================

Below is the code that doesnt want to work

================================================
================================================

PHP Code:



loadVariables("./dll files/q3/a1.dll", "/");
loadVariables("./dll files/q3/a2.dll", "/");
loadVariables("./dll files/q3/a3.dll", "/");
loadVariables("./dll files/q3/a4.dll", "/");
loadVariables("./dll files/q3/a5.dll", "/");
loadVariables("./dll files/q3/a6.dll", "/");
loadVariables("./dll files/q3/a7.dll", "/");
loadVariables("./dll files/q3/a8.dll", "/");
loadVariables("./dll files/q3/a9.dll", "/");
loadVariables("./dll files/q3/a10.dll", "/");
loadVariables("./dll files/q3/a11.dll", "/");
loadVariables("./dll files/q3/a12.dll", "/");
loadVariables("./dll files/q3/a13.dll", "/");
loadVariables("./dll files/q3/a14.dll", "/");
loadVariables("./dll files/q3/a15.dll", "/");

_global.b1 = a1;
_global.b2 = a2;
_global.b3 = a3;
_global.b4 = a4;
_global.b5 = a5;
_global.b6 = a6;
_global.b7 = a7;
_global.b8 = a8;
_global.b9 = a9;
_global.b10 = a10;
_global.b11 = a11;
_global.b12 = a12;
_global.b13 = a13;
_global.b14 = a14;
_global.b15 = a15;

tellTarget ("game") {
    timer = "60";
}
    
tellTarget ("game/board") {
    gotoAndStop(1);
}
tellTarget ("game/board/one") {
    gotoAndStop(1);
    a1 = b1;
}
tellTarget ("game/board/two") {
    gotoAndStop(1);
    a2 = b2;
}
tellTarget ("game/board/three") {
    gotoAndStop(1);
    a3 = b3;
}
tellTarget ("game/board/four") {
    gotoAndStop(1);
    a4 = b4;
}
tellTarget ("game/board/five") {
    gotoAndStop(1);
    a5 = b5;
}
tellTarget ("game/board/six") {
    gotoAndStop(1);
    a6 = b6;
}
tellTarget ("game/board/seven") {
    gotoAndStop(1);
    a7 = b7;
}
tellTarget ("game/board/eight") {
    gotoAndStop(1);
    a8 = b8;
}
tellTarget ("game/board/nine") {
    gotoAndStop(1);
    a9 = b9;
}
tellTarget ("game/board/ten") {
    gotoAndStop(1);
    a10 = b10;
}
tellTarget ("game/board/eleven") {
    gotoAndStop(1);
    a11 = b11;
}
tellTarget ("game/board/twelve") {
    gotoAndStop(1);
    a12 = b12;
}
tellTarget ("game/board/thirteen") {
    gotoAndStop(1);
    a13 = b13;
}
tellTarget ("game/board/fourteen") {
    gotoAndStop(1);
    a14 = b14;
}
tellTarget ("game/board/fifteen") {
    gotoAndStop(1);
    a15 = b15;





================================================
================================================

so far I tried using global variables, _root.<variable>, textboxes linked to glboal variables, having two sets of global variables linked to individual layers.

The only thing that brought me hope was that I can set the global variable to a value and send it to the layer but in no way can I get that global variable to accept the input from load variables.
Please Help

Variable Scope Issues
I have a class that creates a button and contains a property.

Code:
static var myVar:String;
I want the value of this property to be available when I press a different type of button, not defined by my class.


Code:
btn_check.onRelease = function(){
trace(myVar)
}
When I press btn_check, I get the following message in the output window:


Code:
undefined
Thanks

Understanding If.. Else And Variable Scope
Hi all,
In the code below I am looping over an array to create MovieClips, and using an if.. else statement to assign colours to the clips based on XML data. The trace of my XML nodes yields values of 2,1,5,3, meaning that in each case, one of the if statements should have been true and assigned a colour value to the myArray_colour variable, but all four of the resulting clips come out black (the "else" value), and the trace yields a zero for each item. I'm guessing that the problem is that I don't properly understand variable scope, but I'm hoping that someone can tell me if that is indeed the case, and then point me in the right direction. Thanks!








Attach Code

//load XML
var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("xml/sample.xml");
myXML.onLoad = function(success) {
if (success) {

// create array
var myArray:Array = ["a", "b", "c", "d"]

// loop over array
for (var i = 0; i<myArray.length; i++){
//assign a colour value based on values from XML document
trace(myXML.firstChild.childNodes[i].childNodes[3].childNodes);
if (myXML.firstChild.childNodes[i].childNodes[3].childNodes == 1) {
this [myArray[i]+"_colour"] = 0xCC0000}
if (myXML.firstChild.childNodes[i].childNodes[3].childNodes == 2) {
this [myArray[i]+"_colour"] = 0xCC0000;}
if (myXML.firstChild.childNodes[i].childNodes[3].childNodes == 3) {
this [myArray[i]+"_colour"] = 0x0099FF;}
if (myXML.firstChild.childNodes[i].childNodes[3].childNodes == 4) {
this [myArray[i]+"_colour"] = 0xFF9900;}
if (myXML.firstChild.childNodes[i].childNodes[3].childNodes == 5) {
this [myArray[i]+"_colour"] = 0xFFFFFF;}
else {this [myArray[i]+"_colour"] = 0x000000;}
trace (this [myArray[i]+"_colour"]);

// create movie clip
var mc:MovieClip = createEmptyMovieClip([myArray[i]+"_mc"],getNextHighestDepth());
mc.lineStyle(9,this[myArray[i]+"_colour"])
mc.moveTo(100,50*(i+1));
mc.lineTo(101,50*(i+1));
mc.ivar = i;
}}
}

Variable Scope Question
I'm not an experienced Actionscript user so I'm not sure what the normal way to associate a custom class with a movieclip that has been designed in the Flash IDE is.

I made a class called Window to control a movieclip called TestWindow. There are some buttons in the movieclip whose functionality I would like to assign the instance of class Window. How is this supposed to be done?

Here's a representation of what I mean. I hope it is sort of clear. My actual problem is that the local variables are outside the scope of the onPress function but I also think there must be some other way of associating classes with movieclips that have been designed in the IDE.

Thanks







Attach Code

class Window {

private local variables;

constructor(params) {

initialisation of local vars;

attachMovie("clip", "myNewMovie_mc", depth);

myNewMovie_mc.TopBar.onPress = function() {

reference to local variable;

}

}

getters/setters();

}

Class Variable Scope
Take a look at this code:


ActionScript Code:
import mx.utils.Delegate;class Test{  var secret:Number = 50;  function Test(mc:MovieClip)  {    var i:Number;    var new_mc:MovieClip;    for(i = 0; i < 5; i++)    {      new_mc = mc.attachMovie("my_movie", "new_name" + i, mc.getNextHighestDepth(), {_x: i * 50});      new_mc.i = i;      new_mc.onRelease = Delegate.create(this, alert);    }  }  function alert()  {    trace(this.i);    trace(this.secret);  }}


Well... Doesnt work at all... In the class, there isnt a instance of i, so, how may i access this property inside a class function? But i still have an way to access the class.

I could do this way:


ActionScript Code:
class Test{  function Test(mc:MovieClip)  {    var i:Number;    var new_mc:MovieClip;    for(i = 0; i < 5; i++)    {      new_mc = mc.attachMovie("my_movie", "new_name" + i, mc.getNextHighestDepth(), {_x: i * 50});      new_mc.i = i;      new_mc.class = this;      new_mc.onRelease = function()      {        trace(this.i);        this.class.alert();      }    }  }  function alert()  {    trace(this.secret);  }}


But this way, doesnt sounds good

Any suggests?

XML Variable Scope Issue
Hey there. I'm not too strong at coding but I know enough to get things done in actionscript. I recently read some of the primers for XML in Flash and can't completely get it working. The example I chose to work with was the 'inventors' xml file which is read into a simple movie with 2 dynamic textboxes which was found here on kirupa. Worked like a champ, nice and simple.

I replicated it in my own project and it worked, but only on the main timeline. Whenever I tried to target a dynamic text box nested inside a movieclip, nothing would come up. At first, the nested dynamic text box was contained in it's own layer. When that didn't seem to work, I cited another example on the site (regarding an XML-driven .mp3 player i think..) and tried to attach the dynamic text box from the library to a movieclip at runtime...still wouldn't work.

I know the XML data is being loaded properly because the trace commands I output were never undefined and held valid data. Any help at all would be much appreciated!

Here's the xml file :


Code:

<?xml version="1.0"?>
<inventors>
<person>
<name>Thomas Edison</name>
<comment>Inventor of many things such as the incandescent lightbulb.</comment>
</person>
<person>
<name>Doug Engelbart</name>
<comment>Invented the mouse at the Stanford Research Institute</comment>
</person>
</inventors>
and the actionscript (on frame 1 of 'lensFlare' movieclip)


Code:

stop();
var root:MovieClip = this;

function loadXML(loaded) {
if (loaded) {
_root.inventor = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
_root.comments = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
trace(_root.inventor);
var Mc:MovieClip = root.attachMovie("txt_mc", "txt_mc1", 1);
Mc.inventor = _root.inventor;
///here's where I think i'm going wrong in some way
Mc.txt_mc.text = Mc.inventor;
trace(Mc.txt_mc.text);
//txt_comment.text = _root.comments;
} else {
trace("file not loaded!");
}
}
xmlData = new XML();
//xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("inventors.xml");
linkage for the movieClip and the dynamic text box is enabled as well.

Variable Scope Question
I have a flash variable scope question, and I'm not sure how to reference the variable.

In my text file is &myColor=blue

The three movie instances don’t want to change color based on the loaded text variable. Perhaps you can shed some light.

I’m trying to fix this so designers have options for color, but are set with particular brand colors.


Code:

#include "lmc_tween.as"

var fadeTime:Number = 2;

loadText = new LoadVars();
loadText.load("assets/description.txt");
loadText.onLoad = function() {
middle_bg._alpha = 20;
my_color = this.myColor;
switch (my_color) {
case "teal" :
trace("teal");
theColor = "0x156570";
break;
case "blue" :
trace("blue");
theColor = "0x44697D";
break;
case "green" :
trace("green");
theColor = "0x496C60";
break;
case "grey" :
trace("grey");
theColor = "0x666666";
break;
default :
trace("the default value");
theColor = "0x666666";
break;
}
//theColor = 0xFF0000;
top_bg.colorTo(theColor, fadeTime, easeInOut);
middle_bg.colorTo(theColor, fadeTime, easeInOut);
bottom_bg.colorTo(theColor, fadeTime, easeInOut);
};

[F8] Count Variable Scope (?)
Hi

I have a count variable so when I press a button "count" increments (it works)

But what I don't get is how it works here...


Code:
var titlename:String = photos[count].getTitle();
but not here...


Code:
if (_root.userass[count] == _root.answers[count]) {
container.resultsDisplay["indicator"+count].gotoAndStop("correct");

} else {
container.resultsDisplay["indicator"+count].gotoAndStop("fail");
}
any ideas?

thanks

Possible Variable Scope Issue?
I have the following code, where rolloverButtons is a 2-dimensional array.



Code:
for (i = 0; i < rolloverButtons.length; i++)
{
rolloverButtons[i][0].onRollOut = function()
{
rolloverButtons[i][1]._something = something;
}
}
The problem is that within the function called by the onRollOut event, the counter variable i is not recognized, therefore the reference to the movie stored in that element of the array is not recognized. Is there some way to get the value of i into that inner function?

The reason I am using a loop for this is because I have 10 buttons, and don't want to have to write out 10 different functions to control how they behave. Perhaps there is another way of achieving this goal?

Thanks in advance...

Class Variable Scope
I'm somewhat new to writing classes so forgive me if I get some wrong terminology.

I have a MC with a class attached to it, and I have other MCs within that MC. I need those MCs to be able to access variables within the main MC class. Here is a quick'n'dirty:


Code:
class Foo extends MovieClip{private var h:Number;
private var subMC:MovieClip;
function Foo(_h:Number){h = _h;
}

subMC.onEnterFrame = function(){trace(h);
}
}
How can I access variables in the Foo class from another MCs scope? I have tried using static var but aren't they constant regardless of instance?

Create Variable With Another Scope?
How do i create a variable in another scope than the current one?

For example, say i have a MovieClip, mc

i want to create an object within that mc.

so instead of var obj:Object = new Object()

i want to do something this this effect:

var mc.obj:Object = new Object()

effectivly creating that object with the scope of the mc

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