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








Scoping Different Variables


Hello does anyone know how to scope variables in a loop by using variables?

i.e.

I have 4 variables with different values

varName1 = "one";
varName2 = "two";
varName3 = "three";
varName4 = "four";

I want to pass there values to dynamic text fields in different movie clips (already set up) as follows:

for (var i = 1; i<4; i++) {
_root["mov"+i]["textArea" + i].text = varName + i;
}

The last bit varName + i doesnt pass the variables values to text as i want them to???

anyone know what I mean and has an answer?

thanks

Craig




FlashKit > Flash Help > Flash ActionScript
Posted on: 01-20-2005, 12:58 PM


View Complete Forum Thread with Replies

Sponsored Links:

Scoping Variables Aarghh...
for (var i = 2; i<=maxvalue; i++)
{duplicateMovieClip("clip", "clip"+i, i);
....
....
and so on

so you see I want to duplicate a movieclip here as much as 'maxvalue' times. It works fine. But inside the duplicated movieclips is another movieclip/button and its (unique) behaviour is controlled by the following script: (I also placed this in the "for"-loop (?))
...
clipnumber = eval("clip"+i);
clipnumber.submovie.onRelease = function() {
getURL("detailpage"+i,"target");
};
...

but this i variable is not reachable from within the function. I suppose I am making very fundamental mistakes, but can somebody help me out and show me the right way to do this?

thanks guys
Stanley

View Replies !    View Related
Scoping Local Variables
Hi all,

How do I reference a local variable defined in a function?

eg

ActionScript Code:
function MyFunction()
{
    var Obj1:Object = new Object();
   
    trace(Obj1);   //ok
    trace(this["Obj1"]); //not ok
    trace(this.MyFunction["Obj1"]) //nor this
}


I need to be able to programmatically loop through several numbered variables

View Replies !    View Related
Fascinating Scoping-variables Question...
In Flash 5, how do I declare a global variable on the main timeline so that my movieclips can use it?

I've been saying...

var i = 0;

... on main timeline, and I've tried in my clips referring to "i" by specifying level ("_level0.i") and root ("_root.i"), e.g.,...

if (_root.i >= 40){
play();
}

else {
stop();
}

... but it ain't working.

Thanks for any help.

View Replies !    View Related
Scoping Question - Accessing Variables On Stage
I'm having a hard time converting from 2.0 to 3.0, particularly with scoping. I used to wonder why I had to put _root before everything and wished they would redo the scoping in 3.0 but now I have my wish and I'm having problems! I'm studying Colin Mook's book Essential ActionScript but I'm just not getting it. It's probably in the next several hundred pages.

Is there a basic rule of thub for a function within an .as file accessing variables on the stage? I guess I could use a Document Class so that I could use that as a name to target... I used stage.function name but that didn't work... Any basic rules I should keep in mind?

View Replies !    View Related
Class Scoping Issue Can't Access Variables Attached To Mc
Hello,
I'm trying to setup a simple photo gallery class and for some reason the variable that I attach to an MC is not accessible through the function. Here is the code and I the problem area is commented.


Code:
import com.kenElliott.ImageLoader;
import mx.utils.Delegate;

class com.kenElliott.PhotoGallery {
private var thumbContainer:MovieClip;// Thumbnail container
private var mainContainer:MovieClip;// Large Image Container
private var imgs:Array;// Thumbnail array
private var ID:Number;// Interval ID
private var tCount:Number=0;// Thumbmnail iterator
private var tfold:String;// Thumbnails Folder
private var ifold:String;// Images Folder
private var spacing:Number = 10;
private var cImage:MovieClip;// Current interval image container
private var rCount:Number;// Row count

public function PhotoGallery(tc:MovieClip,mc:MovieClip,tf:String,lf:String) {
thumbContainer = tc;
mainContainer = mc;
tfold = tf;
ifold = lf;
}

public function populateThumbnails(i:Array) {
imgs = i;
ID = setInterval(Delegate.create(this,loadOne),500,111);
}

public function loadImage(n) {
trace(this.myLink); // does not trace
trace(this); // traces fine
}

private function loadOne(i:Number) {
var iLoader:ImageLoader = new ImageLoader(tfold+'/'+imgs[tCount],thumbContainer,undefined,Delegate.create(this,centerImage));
iLoader.startLoading();
cImage = iLoader.getImageHolder();
cImage.myLink = imgs[tCount];// set it here
trace(cImage.myLink);// traces fine
cImage._y += spacing;
tCount++;
if(tCount%2) {
cImage._x += spacing;
} else {
cImage._x += (spacing*2)+100;
}
cImage._y += Math.floor((tCount-1)/2)*(75+spacing);
if(tCount>=imgs.length) clearInterval(ID);
}

private function centerImage() {
var mc:MovieClip = _root.createEmptyMovieClip('yo',_root.getNextHighestDepth());
mc.dLink = cImage;
mc.onEnterFrame = function():Void {
if(this.dLink._width < 100) {
this.dLink._x += (100-this.dLink._width)/2;
}
this.removeMovieClip();
}
cImage.onRelease = Delegate.create(cImage,loadImage);
}
}
I tried using the delegate class but it didn't help. Still could not access the data I assigned to cImage.myLink - thanks for any help. Hope someone can help me figure this out.

webg

View Replies !    View Related
Scoping
hi all,

I want know if there are an another way to get the value from a variable if I use the OOP style


//CODE
//---------------------------------------------------
function HeroKeyMovement() {
}
HeroKeyMovement.prototype.init = function() {
this.x = [5, 9];
return this.x;
};
HeroKeyMovement.prototype.onKeyDown = function() {
// IS THIS THE ONLY WAY
trace(this.init()[0]);
};
hero_mc.__proto__ = HeroKeyMovement.prototype;
Key.addListener(hero_mc);
//---------------------------------------------------
//ENDCODE


THANKS

View Replies !    View Related
Help With Scoping
This is a project for school
basically I have to make a movie of a boat, the ocean, the island. The thing is I have to make a priate-eye scope on the whole things

the problem is not all of them on the same layer
the ocean is the top one
the island after
the boat
the scope moving across the screen only showing what's inside the scope ( anything outside is black )

what's the way to make the scope working on every layer?

-----------------------------
by the way the program at school is Flash 5, some people did this in Flash MX but it doesn't work in Flash 5...
-----------------------------

I've found a similar tutorial, but the website isn't working now
its @ http://www.iboost.com/build/software...king/10021.htm


thanks

View Replies !    View Related
AS3 Scoping
I am slowly getting into AS3 and think it is brilliant but I know there are fundamental things I do not understand and this is causing lots of headaches. A lot of it has to do with scoping. The code below is an example. I load some elements from the library into another movieClip. It all works but then I have no idea how best gain access to those movieClips afterwards (please see the comments in the code for more detail).


Code:
package {
// import other classes used
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;

public class cls_gameControls extends MovieClip {

private var gameElementList:Array = new Array(cls_obstacle_Deflector, cls_obstacle_Deflector);
//var account:Object = {name1:"cls_obstacle_Deflector", name2:"cls_obstacle_Deflector"};

private var xPos:Number;
private var yPos:Number;
private var gameElement:MovieClip;
//
private var i:Number;
//public var myScroller_mc:MovieClip;


function cls_gameControls():void {
//
this.xPos = this.myScroller_mc.displayArea.width/2;
//
gameAssetsSetup();
}
//
private function gameAssetsSetup():void {

for (i=0; i<2; i++) {

// here I load the movieClip from the library using the names in the array as reference
gameElement = new gameElementList[i];

// this all works fine ...
gameElement.name = "gameEle"+i;
gameElement.scaleY = gameElement.scaleX = this.myScroller_mc.displayArea.width/gameElement.width;
gameElement.x = xPos;
gameElement.y = gameElement.height+(i*80);
//I move the movieClip to where it should go and it gets there ok ....
this.myScroller_mc.pageMC.addChild(gameElement);

// But then, I don't know how to reference that moveClip from here on
// .... I cannot say this.myScroller_mc.pageMC.gameElement or
// this.myScroller_mc.pageMC[gameElementList[i]]
// even thought the two trace statements give me the same value of "cls_obstacle_Deflector"
trace("?/ "+this.myScroller_mc.pageMC.getChildAt(1+i)+" :: "+gameElement)

// the code below works but I don't understand it ....
var m = this.myScroller_mc.pageMC.getChildAt(1+i)
trace("!: "+typeof(m))
m.x += 30
//
}
//
}
}
}
Please enlighten

View Replies !    View Related
Please Help With Scoping
hi, I have problems understanding scope targeting from inside a function



ActionScript Code:
function setItems(isClosed:Boolean) {
    if (isClosed) {
        for (i=1; i<options_Array.length+1; i++) {
trace (this) // undefined
trace(this._parent) // undefined
trace(_parent) // returns parent, not this timeline
            duplicateMovieClip("text_mc", "text"+i, i);
            this["text"+i]._y = 1.5+(i*20); //doesnt work
            this["text"+i].title_txt.text = options_Array[i];//doesnt work
            this["text"+i].onPress = function() {//doesnt work
                setItems(false);
            };
        }
    } else {
        for (i=options_Array.length-1; i>0; i--) {
            this["text"+i].removeMovieClip();
            back.moveNone("_height", 18, 10);
        }
    }
}


how can I target the duplicated items to set all these values?
I tried to use variable, like
var a = duplicateMovieClip("text_mc", "text"+i, i);
a._y = 1.5+(i*20);

it did not work
Please Help!

View Replies !    View Related
Variable Scoping
Post your pref'd way to simulate the _global attribute of MX in F5.

View Replies !    View Related
Scoping GotoAndPlay
I am trying to call a movie clip from the main timeline. The clip is nested in a group, which is also a symbol. What is the exact syntax? Do I have to refer to the group somehow? I'm using:
instance1.instance2.gotoAndPlay("tag")

thanks,
C

View Replies !    View Related
[F8] Scoping Problems
Hi guys,

I have written a class and ran into some scoping problems


Code:
public function display(pos):Void {
textTarget._alpha = 100;
textTarget.htmlText = "<headline><a href='"+links[pos]+
"' target='_blank'>"+titles[pos]+"</a></headline><br /><br/>"+
descriptions[pos]+"<br />"

}

public function fadeout():Void {
targetClip.onEnterFrame = function() {
//PROBLEM REFERENCING THE TEXTFIELD HERE
if (this.output_ta._alpha >= 0) {
this.output_ta._alpha -= 5;

}
else {
//PROBLEM HERE display(p) not referenced correctly.
display(p);
p++;
delete this.onEnterFrame;
}
}
}




Currently, i need to be able to call display(p) in the onEnterFrame function nested insider the fadeout function.

How do I reference the display(p), since it is at the highest level of the class.

Also, currently the value this.output_ta is hardcoded.

I have output_ta as a textbox nested within a movieclip newsMC on my stage.

How do i refer to the textbox output_ta within the onEnterFrame function?

targetClip references to newsMC
textTarget references to newsMC.output_ta

thanks!

View Replies !    View Related
Having Some Scoping Issues.
Hello all, i am having some trouble working some some XML function and getting some vaules into the root. Maybe someone can help me?

I have this code:

Code:
ladderXML = new XML();
ladderXML.load("ladder.xml");
ladderXML.ignoreWhite = true;
ladderXML.onLoad = extractData;


function extractData(success) {
rootHandler = this.firstChild.childNodes;
gimble = rootHandler[1].attributes.PicURL;
trace(gimble)//works;
}
trace(gimble)//unidentified;
As you can see in my commented code the trace which sits outside of the function is unidentified.

I tried using _root.gimble when setting the variable and calling it but this was giving me the same result, which i find very odd as i thought _root worked from anywhere (although bad practice, i know).

Thanks in advance if you can help me understand.
Turbs.

View Replies !    View Related
Variable Scoping
Hi- I'm new at OOP and this is my first attempt at working with classes and objects in Actionscript. I've run into what I think is a variable scoping issue. I've read a decent amount about it- but I can't seem to apply what I've read to fix this issue.. Maybe my assessment of the problem is wrong. any help would be appreciated..

This is a portion of the main() function of a class:

Code:
public static function main():Void {
photostreamXML.onLoad = function(xmlLoaded:Boolean) {
if(xmlLoaded) {
//code that parses XML into arrays
}
var photoArrLen:Number = photoArray.length;
// loop through arrays created from xml and store them in a multi-dimensional array
for(var b:Number=0;b<photoArrLen;b++) {
completeArray[b] = new Array(photoArray[b], widthArray[b], heightArray[b], captionArray[b], urlArray[b]);
}

/*
* Initializes Gallery
*
*/
loadGallery(completeArray);
}
}
photostreamXML.load("la.xml");
}

This is the function called at the end of the main() function:

Code:
public function loadGallery(photoList:Array) {

var len:Number = photoList.length;
var myclip;
var populate:Object;
i=0;
for (var i = 0; i < len; i++) {
myclip = createEmptyMovieClip("UseMe"+i, 1+i);
populate = new Photo(myclip, photoList[0], photoList[1], photoList[2], photoList[3], photoList[4], true);
}

}
the error I get is: There is no method with the name 'createEmptyMovieClip'. I've tried parent_.createEmptyMovieClip.. and also enclosing with(this) { } around the code.. these seem to get rid of the error- But my photos don't load as they should.. I know the code to load the photos works- It's just when I try to implement it this way that it is failing.. sorry for the length of the post- just trying to make things clear

Thanks in advance for any help!
Alan

View Replies !    View Related
Scoping Problem
Hi guys,

I have written a class and ran into some scoping problems


Code:
public function display(pos):Void {
textTarget._alpha = 100;
textTarget.htmlText = "<headline><a href='"+links[pos]+
"' target='_blank'>"+titles[pos]+"</a></headline><br /><br/>"+
descriptions[pos]+"<br />"

}

public function fadeout():Void {
targetClip.onEnterFrame = function() {
//PROBLEM REFERENCING THE TEXTFIELD HERE
if (this.output_ta._alpha >= 0) {
this.output_ta._alpha -= 5;

}
else {
//PROBLEM HERE display(p) not referenced correctly.
display(p);
p++;
delete this.onEnterFrame;
}
}
}


Currently, i need to be able to call display(p) in the onEnterFrame function nested insider the fadeout function.

How do I reference the display(p), since it is at the highest level of the class.

Also, currently the value this.output_ta is hardcoded.

I have output_ta as a textbox nested within a movieclip newsMC on my stage.

How do i refer to the textbox output_ta within the onEnterFrame function?

targetClip references to newsMC
textTarget references to newsMC.output_ta

thanks!

View Replies !    View Related
Scoping Trouble
Can anyone see why I'm getting 'undefined' on the second trace in this script, but not the first?


ActionScript Code:
_root["picFadeIn_"+_root.image] = new Tween(_root["placeHolder_"+_root.slot+"_"+_root.image], "_alpha", Strong.easeIn, 50, 100, 10, false);

    trace('placeholder: '+_root["placeHolder_"+_root.slot+"_"+_root.image]);

    _root["picFadeIn_"+_root.image].onMotionFinished = function() {
       
                _root["picFadeOut_"+_root.image] = new Tween(_root["placeHolder_"+_root.slot+"_"+_root.image], "_alpha", Strong.easeOut, 100, 0, 25, false);

              trace('placeholder: '+_root["placeHolder_"+_root.slot+"_"+_root.image]);

    }

Any help would be much appreciated.

View Replies !    View Related
Scoping Problem
hey,

i'm working with a .as file and have hit a problem i think has to do with scope.. i have a clip who's .onPress = startScroll ...the startScroll function traces a couple things and sets an interval that calls the moveContent function ..when in the startScroll function i can trace out "this".. and find out where i am.. but when it moves into the moveContent function and i try to trace "this" ..its undefined.. without that i can't find out where contentArea is in relation to it.. i'm trying to move the contentArea.. any suggestions? Thanks!



ActionScript Code:
private function startScroll()
    {
        trace("startScroll");
        trace(_parent._parent.contentArea._y); //traces: 0 (its initial position)
       
        _parent._parent.scrollIntervalID = setInterval(_parent._parent.moveContent,250);
       
    }
    private function moveContent()
    {
        //contentArea._y--; //need something like this here
        trace(this); //traces: undefined
        trace("scrolling");
    }
    private function stopScroll()
    {
        trace("stopScroll");
        clearInterval(_parent._parent.scrollIntervalID);
    }

View Replies !    View Related
Scoping Problem?
Hey all,
I have a function and within that function I call another function. Within the called function I set a variable and then *try* to use it in the main function. The only problem is that when I try to use it always fails . And when I trace it it returns undefined the first time and after that the proper value is there....

I don't know if it's scope or some other problem. Any help or guidance would be wonderful.

AS

Code:
onEnterFrame = function(){
if(count == 0){
box._x = (Stage.width/2) - (box._width/2);
box._y = Stage.height - box._height;

testF();
container = crutch;
container._x = ((Stage.width/2) - (container._width/2)) + centerOffSet;
container._y = Stage.height - container._height - box._height - heightOffSet;

origW = Stage.width;
origH = Stage.height;
if(box._width > 0 && container._width > 0){
count = 1;
}
}else{
if((Stage.width - origW) < 0){
flip = -1;
}else{
flip = 1;
origW = Stage.width;
origH = Stage.height;
}
menuSpeed = 5;
containerSpeed = 8;

menuActions(flip,menuSpeed);
containerActions(flip,containerSpeed);
}
}



function testF(){
rootNode = container_xml.firstChild;
xmlLength = rootNode.childNodes;

for(i=0;i<xmlLength.length; i++){
currentNode = xmlLength[i];
if(parseInt(currentNode.attributes.num) == pageID){
xmlLength = currentNode.childNodes;

for(i=0;i<xmlLength.length; i++){
currentNode = xmlLength[i];
firstKid = currentNode.firstChild;
secondKid = firstKid.nextSibling;
thirdKid = secondKid.nextSibling;
fourthKid = thirdKid.nextSibling;

if(counter == 0){
container = thirdKid.firstChild;
swfName = fourthKid.firstChild;
this.createEmptyMovieClip(container, this.getNextHighestDepth());
this[container].loadMovie(swfName);
this[container._y] = heightOffSet = parseInt(firstKid.firstChild);
this[container._x] = centerOffSet = parseInt(secondKid.firstChild);
counter++;
}
}
}
}
}

View Replies !    View Related
Another Scoping Problem
Scoping has been discussed many times here, but I still can find an answer.

I am not declaring any classes, and on my root timeline I have a simple variable:

ActionScript Code:
var gun_number:int = 1;
on that time line I have couple of movie clips, one inside another.
In the last movie clip I want to trace the gun_number variable, but I am getting
1120: Access of undiffined property gun_number error

How can I make this var into a global var ??

View Replies !    View Related
Scoping Question
How do you scope this


Code:
this.brainWordLen1= 4;
this.brainWordLen2 = 8;
this.brainWordLen3 = 6;
//
this.brainScoreStep = 0
//
braintimer.onEnterFrame = function() {
//
brainScoreStep++
//
this.score += ["brainWordLen"+brainScoreStep]
//
// This is the part that confuses me. If I say
// this["brainWordLen"+brainScoreStep] it refers
// local to the onEnterFrame but
// ["brainWordLen"+brainScoreStep] does not refer
// to e.g. this.brainWordLen3. How should I scope
// this.brainWordLen3 within the onEnterFrame ???
//
}

View Replies !    View Related
Scoping Issue
Okay, a bit of a mouthful here but (I think) my problem is about scoping. I have a class and part of it is an XML object (as a property). The onload handler of the XML object has to be able to modify the data in the parent structure. I have no idea whatsoever how to do this - I may have to resort to some kind of arcane message passing system using the _root scope. Any help is appreciated.
-Mouseit

View Replies !    View Related
Scoping Problem
I have the follwing code. When I call UPDATE_INFO_BOX(); the trace window
gets the correct path to the movie clip, but when this function is called
from the interval, it returns undefined. I guess this is to do with scoping.
Could anyone please tell me where i am going wrong.

Many thanks

mBACK.onPress=function(){
startDrag(this._parent);
trace(this);
vMOUSE_INT=setInterval(UPDATE_INFO_BOX,10);
}
mBACK.onRelease=function(){
stopDrag();
clearInterval(vMOUSE_INT);
}
mBACK.onReleaseOutside=function(){
stopDrag();
clearInterval(vMOUSE_INT);
}

function UPDATE_INFO_BOX(){
txtPOSITION.text=this._x;
trace(this);
}
UPDATE_INFO_BOX();

View Replies !    View Related
Scoping Problem
quote:function sendMsg(s)
{
trace(s);
}

application.onConnect = function() { setInterval(sendMsg, 1000, "test"); }

When using code like that, setInterval can't reach sendMsg()... I know this seems like an incredibly newbie question... but how do I make it work?

I can't seem to figure out the scope of toplevel functions -- never needed to do this because everything else is tucked neatly in classes and it's mostly remoting...

View Replies !    View Related
Scoping Problems, I Think
I have code that works when placed in a keyframe on the main timeline, but doesn't behave the same when it's in a package in an .as file. The linkage is correct for the document and movieclips, but I am missing some step. I'd appreciate any help. I've denoted the specific lines that are generating an error.

package myPackage {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.display.Scene;
import flash.external.ExternalInterface;

public class Marble extends MovieClip{
public function Marble(){
addEventListener(MouseEvent.MOUSE_DOWN, marbleDrag);
addEventListener(MouseEvent.MOUSE_UP, marbleDrop);
}
public function marbleDrag(event:MouseEvent):void {
event.target.startDrag(true);
startX = event.target.x;
startY = event.target.y;
trace(event.target.name);
}
public function marbleDrop(event:MouseEvent):void {
event.target.stopDrag();


//I THINK THESE CREATE ERRORS IN MY SUBSEQUENT CODE
var myTargetName:String = "target" + event.target.name;
var myTargetisplayObject = getChildByName(this.root.myTargetName);


trace(event.target.dropTarget.name,event.target.dr opTarget.parent.name);
if (event.target.dropTarget.parent == myTarget){
trace("target acquired");
event.target.x = myTarget.x;
event.target.y = myTarget.y;
}
else {
trace("target lost");
event.target.x = startX;
event.target.y = startY;
}
}
}
}

View Replies !    View Related
Scoping Fuction
I want to call a fuction which is inside a moviclip through another movie
how can i do this when function is in _root then it works but when i want to call the fuction from a movieclip then the path doesn't work ie
_root.myMc.myFunc()
can any body help

View Replies !    View Related
_currentframe Scoping And Help
Hi,
I am a newbie to flash and actionscripting..

I have a movie that shows a virtual tour of a site, with a cursor that moves around various screenshots, demonstrating features. When it shows something important, I attachMovie a new little MC to the main timeline, using attachmovie. (throughout the movie, there are about 60 different popup MCs)

To do this i stop() the main movie at a desired frame, add an instance of the popup MC to the maintimeline and call attachMovie to that MC. the popup MC plays and then a stop() command and a _root.play() is entered to play the main timeline.

My problem is that i want to enter player controls, (ie PAUSE and PLAY button). I've created two buttons, pause and play, and on(release) can call _root.stop(), but i can't make the attachedmovie stop because i don't know what instance is actually going to be playing at the moment someone presses PAUSE. So far i can create an action in the attached movie, but can never track the _currentframe of that clip (i believe the _currentframe just gives me the root frame the MC was attached to). I want to know how i can increment through a MC attached to a stopped main movie clip, using this._currentframe + 1. (i want to do this so i can check the state of a variable i have set called bPlaying. if false, then i don't want to increment or go, if true, then go to _currentframe + 1 and do the check again)

this sounds pretty wack, I may not have constructed the main movie and attachmovie correctly, or it just may not be the best way to solve this, but i would appreciate any or all help in the matter. any solutions or just knowledge on how to create this thing would be great. i have looked all over for tutorials, but haven't found much cept one on flashkit that i was unable to use. thanks in advance,

you can see an example of what it looks like here, its unfinished right now.
http://www.mixonic.com/demo.jsp

thanks for real yo.
ameet

View Replies !    View Related
MovieClip Scoping
Hi, I am experiencing some issues while scripting external classes and tries to scope a MovieClip which lays in the library of a .fla. I am linkaging the MovieClip with "myMc" as identifier. But how can use this movieclip in my class and make it appear on the screen? Make a new MovieClip and attach my movieclip to that one? I'm a bit confused when it comes to MovieClip scoping, would be pleased if somebody could explain it clearly to me. Thanks in advance! :)

View Replies !    View Related
Variable Scoping In Flash 4
Would anyone know what could be happening here,
according to all the notes I looked up variables are all global on the same timeline,

I have two frames with the following scripts ....

Frame1Label(InitIteration)
----------------------------
Set Variable: "NextCode" = 12345
Set Variable: "ReturnFrame" = "ParseCode"
Trace ("<<1>>" & NextCode & "::" & CodeDepth)
Go to and Stop ("ParseLine")

i.e) NextCode is hardcoded to "12345" and displayed

Frame2 Label(ParseLine)
----------------------------
Trace ("<<2>>" & NextCode)
Set Variable: "ReturnTo" = ReturnFrame
Set Variable: "ReturnFrame" = "ParseLineA"
Go to and Stop ("StripPadding")

When I execute the code above it works fine the first time

(TRACE OF NextCode FROM FRAME 1)
<<1>>12345::1
(TRACE OF NextCode FROM FRAME 2)
<<2>>12345

Any other execution results in ...
(TRACE OF NextCode FROM FRAME 1)
<<1>>12345::1
(TRACE OF NextCode FROM FRAME 2)
<<2>><-- EXPECTED TO FIND 12345 HERE ALSO!

I can't figure out why the hardcoded value would be "missing" between the frames ??
Theres no other code between the Frames!!
Could it be a scoping issue ?

View Replies !    View Related
Quick Scoping Question
When you create a function at the root level, then call the function in a movie clip, then have variables that are used in the function without _root or anything, does it use variables in the root level or in the movie clip? If you're not really sure what I'm saying, here's an example:


Code:
function food() {
if (dog == 1) {
cat._visible = true;
} else if (dog == 2) {
cat._visible = false;
}
If you called that function in a movie clip, but the dog variable and the cat movie clip are at the root level, would it work?

View Replies !    View Related
Rudimentary Scoping Problem
hi

i'm having a very annoying flash mx problem tracing variables within movie clips on my main timeline that is driving me nuts!

i have created a movie clip "circle" with the variable "radius = 12;" on the first frame of the clip.

i place a named instance (crc) of this movie clip on the stage and on the first frame of the main timeline i put a "trace (crc.radius);". this returns "undefined" in the output window when i test the movie. what gives?

if someone could set me straight i would be grateful.
thanks

View Replies !    View Related
[help] _global Scoping Issue
Hi:
I have this strange problem when using _global to reference a variable in FMX.
in the first frame of tha main timeline i have declared a variable, _global.content="hi, i'm the content"; it renders correctly in a dynamic html text field. But when i try to change the content with a button, like on (release){_global.content="i'm the new text";}, it won't do a thing... if i replace _global with _root it works, though. I want to further understand how to use the _global thing, if somebody knows what i'm doing wrong, i'll be very thankful.

Cheers!

Sir Patroclo

View Replies !    View Related
Scoping Issue -UI Components
I'm building a multiple choice question page. On it I'm using textfields, checkbox and buttons. The question and distractors are added to respective arrays, and are being added to the stage. Actually looks good. My problem is the running through a loop to check which checkbox has been selected.

Let me start out with how I'm adding each component to the stage. The code below runs through an object/array. It first adds the textfield element (the question) to the stage, then it adds several movieclips, each containing its own checkbox and textfield. It appropriately positions it, then finally it adds two buttons (Reset and Submit).

Code:
public function initQuestion():void
{
//Place the question and distractors on the screen. Utilize the shared checkButton MC
var questionText:TextField = new TextField();
questionText.autoSize = TextFieldAutoSize.LEFT;
questionText.selectable = false;
questionText.wordWrap = true;
questionText.multiline = true;
questionText.border = false;
questionText.height = 22;

questionText.x = _initPosition.x;
questionText.y = _initPosition.y;
questionText.width = _initPosition.w;
questionText.defaultTextFormat = _formatObj['blackBoldTxtFormat']
questionText.htmlText = _questData.question;
_target.addChild(questionText);

//Place the distractors with the checkButtons
_distractors = [];

for(var a=0; a < _questData.distractors.length;a++)
{
_distractors[a] = new MovieClip();
_distractors[a] = createDistractor(a);
_distractors[a].id = a;

//Position me before adding
_distractors[a].x = _initPosition.x + 10;
var distractorStartY:Number = _initPosition.y + questionText.height + 10;
if(a == 0)
{
_distractors[a].y = distractorStartY;
}
else
{
_distractors[a].y = _distractors[a-1].y + _distractors[a-1].fullHeight + 5;
}

_distractors[a].addEventListener(Event.CHANGE, showMe);

//Finally add me to the screen
_target.addChild(_distractors[a]);
}

//To complete the mix, we need to add the Reset and Submit buttons
var resetBtn = new Button();
resetBtn.x = 564; resetBtn.y = 538; resetBtn.label = "Reset";
resetBtn.addEventListener(ComponentEvent.BUTTON_DOWN, resetButton);
_target.addChild(resetBtn);

var submitBtn = new Button();
submitBtn.x = 671; submitBtn.y = 538; submitBtn.label = "Submit";
submitBtn.addEventListener(ComponentEvent.BUTTON_DOWN, submitButton);
_target.addChild(submitBtn);
}
This all works fine. The first of my problem is when the RESET button is click, it should uncheck any checked checkbox. I can't seem to figure out the score to identify the checkbox within the movieclip. Can anyone assist me on this?

Thanks in advance.

View Replies !    View Related
Scoping Issue And Function
Hi:

Can someone help me with a scoping issue?

SWF A is being loaded into SWF B. Currently, there's a function located in SWF A that is triggered by a user clicking on a movieclip in SWF A. Basically, I am trying to make it trigger from a button in SWF B, instead of triggering by a button in SWF A.

When a user clicks Button B (located on SWF B), I would like it to call the function located in SWF A. This function cause a menu to slide from the left side.

Thanks,
Loren

View Replies !    View Related
SetInterval Scoping Issue, Please Help
Can someone explain why I can't read the variables in the dummy class below?
(I wrote the class below to try to quickly convey my problem without asking you all to go through my own, longer classes that are not getting along nicely with setinterval)


class Test{
private var myVariable:Number = 0;

public function Test(){
setInterval(functionOne,500 );
}


function functionTwo():Number{
myVariable++;
trace('from functionTwo myVariable : '+myVariable);
return myVariable;
}


function functionOne(){
var test2:Number =functionTwo();
trace('test2 ' +test2);
}

}

View Replies !    View Related
Weird Object Scoping
There's a weird thign happening in my as 2.0 class. here's the code first(forgive me if it's a bit long)


Code:
public function Game() {
//init game variables
wordNum = 0;
level = 1;
speed = 3;

var parentObj:Object = this;
//load the words into the arrays
dictioLoader = new LoadVars();
dictioLoader.onLoad = function(success) {
fourLetters = this.four_letters.split('|');
fiveLetters = this.five_letters.split('|');
//_global.trace(fourLetters);
//_global.trace(fiveLetters);
parentObj.createWord(fourLetters);
}

dictioLoader.load("words.php");
}

private function createWord(wordList:Array):Void {
//shuffle wordlist
Methods.arrShuffle(wordList);

//make a new word
newWord = new Word(wordList[wordNum]);
var wordLength:Number = newWord.length;
var shuffledWord:String = newWord.shuffle();
_root.answerField.text = ""; //clears answerfield

_root.createEmptyMovieClip("currWord"+wordNum,_root.getNextHighestDepth());

for(var i:Number=0;i<wordLength;i++) {
_root["currWord"+wordNum].attachMovie("singleChar","char"+i,_root["currWord"+wordNum].getNextHighestDepth());
_root["currWord"+wordNum]["char"+i].wordTxt.text = shuffledWord.charAt(i).toUpperCase();
_root["currWord"+wordNum]["char"+i]._x = 10+(_root["currWord"+wordNum]["char"+i]._width * i);
_root["currWord"+wordNum]["char"+i]._y = 10;
_root["currWord"+wordNum].myWord = newWord.getAnswer();
}

var parentObj:Object = this;

_root["currWord"+wordNum].onEnterFrame = function() {
if(_root.answerField.text.toUpperCase() == this.myWord.toUpperCase() ) {
this.removeMovieClip();
parentObj.createWord(parentObj.getCurrentList());
}

if((this._y+this._height) >= 330) {
this._y = 350-this._height;
} else {
this._y += parentObj.level*parentObj.speed;
}
}
}

public function getCurrentList():Array {
if(level <= 5) {
return fourLetters;
} else if(level <= 10) {
return fiveLetters;
} else if(level <= 15) {
trace("six letters");
} else {
trace("seven letters");
}
}
}
anyways, the problem is i cant get the fourLetters array. What this program does is create a jumbled word which falls down the screen. when you type the answer correctly, another word appears etc.

problem is, when i call creatword again and input parentObj.fourLetters or parentObj.getCurrentList() as a parameter, it says it is undefined. it worked the first time but why not the second time? what happens to my array during this time?

any help would be appreciated. Thanks!

View Replies !    View Related
Possible Class Scoping Issue...not Sure
I have a problem with some classes I've created and I can't seem to figure out what's going on. I have 3 custom classes (call them class_a, class_b, and class_c). Each class_a object has (among other things) an array of class_b objects in it. Each class_b object has an array of class_c objects in it. The problem I'm having is that I can access the properties of the class_b objects inside class_a, but it won't call any of the public member functions.

Here's an example to illustrate the issue:

Code:
class class_a {
public var class_b_arr:Array;

public function send_to_class_b(txt_in:String)
{
for(var x = 0; x < class_b_arr; x++)
{
class_b_arr[x].from_class_a(txt_in);
}
}
}
NOTE: these classes are populated from AS code that I have not pasted here.
Inside class_b would be the function from_class_a. However, this function is never called. It is as if, from inside class_a you can not see the class_b members. However, I can see the class member variables (I've done some testing on this), so it's only the functions (methods) that I'm having trouble with. Am I doing something wrong or is this a known issue?

Thanks,

View Replies !    View Related
ClearInterval And Scoping Problem.
Hi guys,

I am currently trying to solve this problem, but can't seem to find a way to get ClearInterval to work here.

Note that a lot of stuff has been ommited to simplicity

Code:
function loader(clip:String):Void{

//Create MovieClipLoader object
var clipLoader:MovieClipLoader = new MovieClipLoader();

//Create listener object
var loadListener:Object = new Object();

//Remove any stray clips
if (targetClip){
//Fade out targetClip
var targetClipFadeOutInterval:Number = setInterval(targetClipFadeOut, 10);
}
else{
loaderStart();
}

/////////////////////////////////////////////////

function targetClipFadeOut():Void{
if (targetClip._alpha >= 0){
targetClip._alpha -=5
updateAfterEvent;
}
else{
clipLoader.removeListener(loadListener);
clearInterval(targetClipFadeOutInterval);
removeMovieClip(targetClip);
trace(targetClipFadeOutInterval); //RETURNS A NUMBER!????
trace(targetClip);
loaderStart();
}
}
Any ideas?

Cheers!

View Replies !    View Related
AS2 Class Scoping Problem?
Hello,

I *think* I have a problem in my scoping, in one of my classes but I can't figure out what I'm doing wrong. I'm trying use a function to attatch a movieclip with an onRelease function that recursively calls the original function and then finally removes itself from the stage. It does everything just fine except for the function call, which it can't seem to find. Does it have something to do with how deeply nested my declaration of cf_mc.yes_mc.onRelease is within this code? If so, why does the scoping hack seem to work in the trace action just one line above?


ActionScript Code:
function init(n:String,m:Array){
        nme=n;
        msg=m;
        cCount=0;
        self=this; // should take care of scoping issues.      
    }
   
   
    function fillBox(n:String,m:Array,b:MovieClip){
        var s = self; // give this function a local variable for scoping purposes
        var bn = b.attachMovie("advanceMC","text_btn",b.getNextHighestDepth());
        bn.onRelease = function(){
           
            if((++s.cCount) >= m.length){// "s" scoping works here
               
                //irrelevant code
               
            }else{
                if(typeof(m[s.cCount])=="number"){// "s" scoping works here
                    var nn:Number=m[s.cCount];// "s" scoping works here
                    trace(nn);
                    if(nn==0){
                       
                        // "s" scoping works here
                        var cf:MovieClip = s.attachMovie("confirmMC","confirm_mc",s.getNextHighestDepth());
                                               
                        var yes_mc:MovieClip; // this is in cf already           
                       
                        cf.yes_mc.onRelease = function(){
                            s.optionCounter = 0;// "s" scoping works here
                            try{
                                trace(s._name);// "s" scoping works here
                               
                                var tf:Boolean = s.fillBox(n,m,b);// BUT NOT HERE?!
                                if(!tf){
                                    throw new Error("couldn't find function");
                                }
                            }
                            finally{
                                s.fillBox(n,m,b);//Not here either, of course.
                                cf.removeMovieClip();
                            }
                        }                  
                    }
                }
            }      
        }
    }

View Replies !    View Related
Help With Variable Scoping Problem?
I have defined a global variable in the first frame of a movie like:

myfilename

which is a string containing something like:

nextmovie.swf

which is a movie in the same directory as the current movie.

I have attached code to a button:

on (press) {

trace (myfilename);
loadMovieNum(myfilename,0);
}

trace returns nextmovie.swf when the button is clicked which is correct.

but then undefined is returned and the next movie fails to load.

If I use this technique of passing a variable to loadMovieNum outside of the on (press) it works fine.

Apparently myfilename loses its scope at a critical moment here due to the on (press) method?

Can anyone explain this to me? Do I need to write an event handler instead? (i'm not that good at this and that's more complicated from my experience so far).

TIA

Craig

View Replies !    View Related
_global Scoping Issue
Hi:
I have this strange problem when using _global to reference a variable in FMX.
in the first frame of tha main timeline i have declared a variable, _global.content="hi, i'm the content"; it renders correctly in a dynamic html text field. But when i try to change the content with a button, like on (release){_global.content="i'm the new text";}, it won't do a thing... if i replace _global with _root it works, though. I want to further understand how to use the _global thing, if somebody knows what i'm doing wrong, i'll be very thankful.

Cheers!

Sir Patroclo

View Replies !    View Related
Scoping & Filter Problem
So here's the idea. RIght now, I'd like to be able to have my mc "mainPiece" blur in and out using the flash.filters in AS. I think my problem is scoping. Before I turned it into a function, it was working fine as a static filter (non-animated). However, I'd like to be able to control that. Please take a look at the code and tell me what I can do about it.

theInit = 1;
for (i=1; i<=3; i++) {
this["myBlur"+i] = new flash.filters.BlurFilter(i*4, i*4, 1);
}
function fadeBlur() {
var myTempFilters:Array = mainPiece.filters;
myTempFilters[0] = (this["myBlur"+theInit]);
mainPiece.filters = myTempFilters;
if (theInit == 3) {
theInit--;
} else {
theInit++;
}
}
setInterval(fadeBlur, 20);

View Replies !    View Related
Scoping, MyClass, And ContextMenu
I have a class where I'm defining a context menu. The odd thing is, when I call the function, I can't call any variables from outside the function. The context menu calls the function correctly, but the scoping is all wonkey. Is there a way around this?

function checkIt() {
TEST = "test"
trace(TEST);
}
//////////// traces undefined

function checkIt() {
var TEST = "test"
trace(TEST);
}
//////////// traces "test"

I've tried referencing all readily available variables, but due to the way its formatted - will I be forced to use _root variables? Or is there a better way I'm not seeing?

View Replies !    View Related
ScrollPane Scoping Confusion
Hi,
Any enlightenment on this would be greatly appreciated. I'm transitioning to AS3 but not getting something.

I am loading a .swf into a ScrollPane using AS3. I'm also loading the same .swf into a UILoader for use as a thumbnail .
My problem is that I can't rename the content dynamically so I can discern which item I'm dispatching my mouse events from. My events dispatch correctly, but my event target names are like "instance24" etc.

When I try to rename after loading is complete, I get the error below:







Attach Code

----------------------------

Error: Error #2078: The name property of a Timeline-placed object cannot be modified.
at flash.display::DisplayObject/set name()
at DisplayObjTest_fla::MainTimeline/scaleMyContent()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at fl.containers::ScrollPane/fl.containers:ScrollPane::passEvent()
at fl.containers::ScrollPane/fl.containers:ScrollPane::onContentLoad()

-----------------------------

View Replies !    View Related
[FMX2004] Scoping Issue?
I seem to have a little problem


PHP Code:



class ListContainer extends MovieClip{
    var maxElements:Number;
    var topItem:Number;
    var xml:XML;
    var n:Number;
    var array:Array = new Array();
    var all:Number;
    function ListContainer(myMax:Number,myURL:String){
        this.maxElements = myMax;
        this.topItem = 0;
        readArray(myURL);
        }
    function readArray(xmlUrl:String):Void{trace("readArray-called")
        xml = new XML();
        xml.onLoad = function(s:Boolean){
        if(s)if(this.firstChild.childNodes[0]!=undefined){
        trace(drawItems())//THIS IS THE PROBLEM![returns undefined]
        n=0;
        array = new Array();
        do array[n] = this.firstChild.childNodes[n].attributes;
        while(this.firstChild.childNodes[++n].nodeName != undefined );
        var all:Number = n;
        this.drawItems();
        }else{//empty XML
            }
        }
        xml.load(xmlUrl);
        }
    function drawItems():Void{trace("drawItem-called");
        for(var i:Number=0;i<maxElements+topItem+1;i++)
            this["e"+i].removeMovieClip();
        var offsetY:Number = -85;
        var offsetX:Number = 55;
        n = topItem;
        var depth:Number = 0;
        do{
        array[n]._x = offsetX;
        array[n]._y = offsetY+(14*(n-topItem));
        this.attachMovie("element_db","e"+n,depth++,array[n]);
        n++;}while(n != maxElements+topItem && n != all);
        }
        





So it never traces drawItem-called! The way i figure it since this traced from within readArray traces the first line of xml, if anyone can help a begginer to AS2 Classes i hould really apreciate it.
Thanks!

View Replies !    View Related
Problem With Scoping OnMotionFinished
I'm having a bit of trouble figuring out why I can't trigger the function playUntil, which is another private function in this class, in this snippet. This is all residing in a class, and I'm wondering if that is what is making things tricky. Any help would be great. I tried tracing out currentTween.obj as well as currentDestination, both of which return undefined. Any help would be tremendous.

private function processListenerInfo( listenerInfo:String ):Void {
setCurrentDestinationTo( listenerInfo );
if (( currentDestination != currentLocation ) && (currentDestination)) {
currentTween = new Tween(chapterSpawnLocation, "_alpha", Strong.easeIn, chapterSpawnLocation._alpha, 0, .4, true);
currentTween.onMotionFinished = function() {
playUntil( currentDestination );
}
}
}

View Replies !    View Related
[FMX2004] Scoping Issue?
I seem to have a little problem


PHP Code:



class ListContainer extends MovieClip{
    var maxElements:Number;
    var topItem:Number;
    var xml:XML;
    var n:Number;
    var array:Array = new Array();
    var all:Number;
    function ListContainer(myMax:Number,myURL:String){
        this.maxElements = myMax;
        this.topItem = 0;
        readArray(myURL);
        }
    function readArray(xmlUrl:String):Void{trace("readArray-called")
        xml = new XML();
        xml.onLoad = function(s:Boolean){
        if(s)if(this.firstChild.childNodes[0]!=undefined){
        trace(drawItems())//THIS IS THE PROBLEM![returns undefined]
        n=0;
        array = new Array();
        do array[n] = this.firstChild.childNodes[n].attributes;
        while(this.firstChild.childNodes[++n].nodeName != undefined );
        var all:Number = n;
        this.drawItems();
        }else{//empty XML
            }
        }
        xml.load(xmlUrl);
        }
    function drawItems():Void{trace("drawItem-called");
        for(var i:Number=0;i<maxElements+topItem+1;i++)
            this["e"+i].removeMovieClip();
        var offsetY:Number = -85;
        var offsetX:Number = 55;
        n = topItem;
        var depth:Number = 0;
        do{
        array[n]._x = offsetX;
        array[n]._y = offsetY+(14*(n-topItem));
        this.attachMovie("element_db","e"+n,depth++,array[n]);
        n++;}while(n != maxElements+topItem && n != all);
        }
        





So it never traces drawItem-called! The way i figure it since this traced from within readArray traces the first line of xml, if anyone can help a begginer to AS2 Classes i hould really apreciate it.
Thanks!

View Replies !    View Related
Event Object Scoping
Heres what I am trying to do. I have a function that uses loadVars. Once all the Vars are loaded a custom event scenario is used to broadcast to it's registered listener. The event handler resides outside of the function on another frame. FYI: For testing purposes if the event handler is inside the function it works fine. However when it's outside of the function I don't know how to scope to the listener obj. This code below shows the structure that I need to use.


Code:

FRAME 1:
varLoader =function() {
//LoadvVar stuff here

localRef.onLoad= function(success) {
if (success){
varLoadStatus = new Object();
ASBroadcaster.initialize (varLoadStatus);

loadChecker = new Object();

varLoadStatus.addListener (loadChecker);
varLoadStatus.broadcastMessage("onVarsLoaded");
}
}
}


FRAME 2:
loadChecker.onVarsLoaded = function() {
//any code here
trace("Event has worked!");
}

View Replies !    View Related
New To Flash - Scoping Issue
Actionscript Code:
function loadXML()
{
    var book_xml:XML;
   
    var urlLoader:URLLoader=new URLLoader();
    var urlRequest:URLRequest=new URLRequest("stories.xml");
   
    urlLoader.addEventListener(Event.COMPLETE, completeLoading);
    urlLoader.load(urlRequest);
    var holder = "";
    function completeLoading(event:Event):void {
        //when loading of XML completed, the data can
        //go into the internal variable of type XML
        book_xml=new XML(urlLoader.data);
        //display the XML object book_xml as a text
        //inside text area myxml_ta
        holder = book_xml.toString();
        // if i were to do the trace here it would output properly
    }
    // tracing here doesnt output the string
    trace(holder);
}

I can understand what's going on here, and why my XML isn't output. But essentially I need to access that XML outside of the callback function and return it. Is this possible? Is there a naughty way of getting around the scoping issue ?

View Replies !    View Related
Scoping Issue With A Function
Hi:

Can someone help me with a scoping issue?

SWF A is being loaded into SWF B. Currently, there's a function located in SWF A that is triggered by a user clicking on a movieclip in SWF A. Basically, I am trying to make it trigger from a button in SWF B, instead of triggering by a button in SWF A.

When a user clicks Button B (located on SWF B), I would like it to call the function located in SWF A. This function cause a menu to slide from the left side.

Thanks,
Loren

View Replies !    View Related
Flv/attachAudio Scoping Wierdness
Howdy,

Encountered something odd when using attachAudio to control the volume of a netstream from within a class.

Using the following code:
Code:

   private function init():Void{
      netCon = new NetConnection();
      netCon.connect(null);
      netStr = new NetStream(netCon);
      netStr.setBufferTime(buffer);
      container.screen_mc.attachVideo(netStr);
      setAudio();
   }
   
   private function setAudio():Void{
      var myClip:MovieClip =     
                container.createEmptyMovieClip("audio_mc", container.getNextHighestDepth());
      myClip.attachAudio(netStr);
      audio:Sound = new Sound(myClip);
      audio.setVolume(0);
   }

The audio var is declared before the constructor, and it doesn't allow me to control the audio UNLESS I declare the audio var within the setAudio method as a local var. I need it to be accessable from other methods so this is no good to me.

Anyone have any ideas?

View Replies !    View Related
Help Needed Scoping LoadVars Object
I am creating the LoadVars object within a function so that I know the user defined input fields (user_name and password) are allready filled out.

the onLoad function should have access to the LoadVars object by default but for some reason I can't use any of its properties? what am i doing wrong?

Thanks for any help

<newb>

// check authorization
function login() {
// get user input
user_name = _root.content.user_name;
password = _root.content.password;

// Init object for data
_global.auth_data = new LoadVars();
auth_data.load("function_library/flash_login.php?user_name=" +user_name+ "&password=" +password);
auth_data.onLoad = check_user;

// Execute php query
_root.connect.auth_data.sendAndLoad("function_libr ary/flash_login.php", auth_data, "POST");
}

function check_user(auth_data) {
_root.connect.connection_status = auth_data.user_name;
//if (!authorize.error.length) {
//_root.connect.connection_status = "+ Authorization Established +";
//gotoAndPlay("access");
}

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved