Scope Problems
Hey everyone. I'm using Lee's full browser tut for my main page of a web site. I want to load external swf's into the main page (and use pre loaders among other things) but I cannot seem to get the scope right. I had it working before full browser. I used "main" as the centered MC instead of "cover" like Lee. My swf's load into "container" which is inside of "main". Can anyone give me some insight....PS I'm a total noob so don't laugh at my comments in the code! javascript:emoticon(':oops:')Main AS:Code: stop();/////////////////////FULL BROWSER FLASH CODE: Fills browser window 100% with "tile" gif/////////////////////// Must add this CSS code in HTML head tag to get rid of the border:/*<style>body {margin:0px;padding:0px}</style>*//////////////////////////////////////import flash.display.BitmapData;var centerX:Number = main._width/2;var centerY:Number = main._height/2;main._x = (Stage.width/2)-centerX;main._y = (Stage.height/2)-centerY;var tile:BitmapData = BitmapData.loadBitmap("tile");function fillBG() { this.beginBitmapFill(tile); this.moveTo(0, 0); this.lineTo(Stage.width, 0); this.lineTo(Stage.width, Stage.height); this.lineTo(0, Stage.height); this.lineTo(0, 0); this.endFill();}fillBG();var stageL:Object = new Object();stageL.onResize = function() { fillBG(); var centerX:Number = main._width/2; var centerY:Number = main._height/2; main._x = (Stage.width/2)-centerX; main._y = (Stage.height/2)-centerY;};Stage.addListener(stageL);////this sets up the button array to load in different text descriptions into the same button movie clipvar buttonTextArray:Array = new Array("home", "about", "clients", "appointments", "contact");//////this tells which text in the array to go to which button: 0 is really #1this.main.menu.b1.myText.text = buttonTextArray[0];this.main.menu.b2.myText.text = buttonTextArray[1];this.main.menu.b3.myText.text = buttonTextArray[2];this.main.menu.b4.myText.text = buttonTextArray[3];this.main.menu.b5.myText.text = buttonTextArray[4];target = this;/////////////////////////////////////////////////////////////////this makes sure "home" loads by default into the "main" file ////////////////////////_root.currMovie = "home";main.container.loadMovie(_root.currMovie+".swf");var mcl:MovieClipLoader = new MovieClipLoader();mcl.loadClip(currMovie+".swf", main.container);//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////These are all the navigation buttons that load in the external SWF's...////////////////////the "if, else" statement allows for the intro and outro animation on the timeline of each swfthis.main.menu.b1.onRelease = function() { if (_root.currMovie == undefined) { _root.currMovie = "home"; mcl.loadClip("HOME/home.swf", main.container); } else if (_root.currMovie != "home") { if (main.container._currentframe>=main.container.midframe) { _root.currMovie = "home"; main.container.play(); } }};And on my external "home" page I have the midframe code etc. which you can see if you DL the files:[url]http://download.yousendit.com/D745AB4E4D6614BD[/url] :oops:
General Flash
Posted on: Wed Oct 18, 2006 2:57 am
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
[flash8] Is This An Issue With Scope? No, Not Bad Breath, The Other Kind Of Scope
I feel like such an idiot. This *should* have been a really simple operation and it's turned into an hour-long issue. I've been trying to migrate from putting my button code on buttons and move the code onto the timeline instead. However in this instance it no workie . The following code, specified for cancelMC affects every other button in this scene as if I'd written the code with(this){.
If someone would please just scan this code, and/or look at the picture and tell me what key ingredient I am missing I would really appreciate it:
ActionScript Code:
with(this.cancelMC){ onRollOver = function(){ this.ExplainMC.gotoAndStop("cancel"); } onRollOut = function(){ this.ExplainMC.gotoAndStop("void"); } onRelease = onReleaseOutside = function(){ _root.searchPanelMC.gotoAndStop(15); gotoAndStop("user"); } }
the code is on the timeline and so is the button (cancelMC). However, the code is on the first frame and the button exists on multiple frames thereafter. Does this matter? Does that put the button outside the scope of the code? I tried an onEnterFrame to no effect.
Huh?: MyFunc = {func:func, Scope:scope, Args:args }
Hi,
I've seen this strang syntax used for functions (I think that's what I've seen anyway). Things like:
Code:
myFunc = {func:func, scope:scope, args:args };
in the above I think func is a function and scope is the critter that is supposed to call the function and args are the arguments? But I dont really understand how it works. How do you call myFunc in the above? How do you write a function using this syntax?
Or am I totally off here?
Can anyone help?
I Need Some Scope (pu)
Howdy
I'm doing a dyn. .txt based "news-reader"...
5 dyn txt files, 5 buttons, one dyn text field (box)
with variable name of "display".
My site is based on a main page at level_0, and I load swf's throughout to
various levels. My news reader works great in a stand alone config (when
testing in ie or flash player). When in the main movie, it fails to load txt files when i call it up to
a level, although it does load the buttons and it's
graphical elements. Code is as written
Heres the code on the _root of the news reader:
frame 1 of root,
loadVariablesNum ("content.txt", 0);
loadVariablesNum ("content2.txt", 0);
loadVariablesNum ("content3.txt", 0);
loadVariablesNum ("content4.txt", 0);
loadVariablesNum ("content5.txt", 0);
this._x=170
this._y=20
txt's are named as above...content.txt, etc.
first line inside the text files read:
dynamicText=<HTML><BODY>This is where we go to drink ale...(snip)
dynamicText2=<HTML><BODY>That is where we go to sober up...(snip)
etc.
button code goes:
on (release) {
display = dynamicText5, 5;
}
etc.
Again, this thang works great as long as I fire it up by itself. Inside my
main movie, it loads to the level to which I call it, including all graphic
elements, but onRelease, nothing happens with the txt's which should rear
their beautious heads.
Ideally, I would have my main page at level_0,
a nav swf at level_1 that has a button that calls the reader into level_3.
I've got the feeling this is a variable scope issue, but alas, rank amature
here...
Thanks in advance for any comments, codes or critiques.
Willy B.
(ps, this "txt.reader" is closely based on the "Regenerate" tutorial
in foe nmf 2002 annual).
Scope
Ok, maybe I am having a scope problem here?
can't get...
_level20.button1_mc.onRelease = function() {
play();
};
to give me the hand cursor. This code is on level 1. "interface.swf" is in level 20 and loads (I see the graphics). MC, instance name, "button1_mc" is on level 20's root. Yet, I rollover it...nothin'. But this works in a swf without using levels. (minus the_level20. code)
Can you have that code on level one, defining an event for a button on level 20? What's wrong?
??
Thanks,
rez
Scope
i'm makin a fps shooter where u use a sniper in 1 level and iono how 2 make one. i figure u have 2 say sumthin in the actionscript to tell it to go to a certain magnifacation if its in a certain area (where the scope is) but iono how 2 do this. can anyone help me. P.S. i was gonna put this question on games but it seemed 2 be a newbie kind of qwestion. iono. mayB i shuldnt have. srry
A Little Scope Help?
Hi all,
Think I could use a little scope help here. My function below splits a string, then attaches an mc for each item in the resulting array. A trace of the array contents returns correctly in the loadNavItems function. Within this function I have an onRelease function, but cannot seem to target the array the same way - trace returns undefined. What am I missing?
ActionScript Code:
function loadNavItems(navItems:String) {
var navItems_array:Array = navItems.split(",");
for (var i = 0; i<navItems_array.length; i++) {
trace(navItems_array[i]); // traces correctly
var navTxt:Object = dfSite.navHolder_mc.nav_mc.attachMovie("navTxt_mc", "navTxt"+i, i);
navTxt.navBtn_mc.onRelease = function(){
trace("linkTo "+navItems_array[i]); // undefined
}
}
}
Thanks for any help.
Scope
I am trying to understand the scope of different things and have written a simple class and fla to use it.
Code:
class instance {
public function getScope(){
trace("from class: " + _root);
trace("from class: this._parent);
trace("from class: " + this);
}
}
Code:
trace(_root);
trace(this);
var scope:instance = new instance();
scope.getScope();
The output I get it:
Code:
_level0
_level0
from class: _level0
undefined
from class: [object Object]
It all makes sense except for the last line, why does it say that? Everything is a subclass of object right? So I guess it makes sense for this intstance, but say I change me class to extend MovieClip, then it would seem that the last line in the out put should say object MovieClip or something like that.
And then why does this._parent return undefined? Isn't that the same as _root in this case?
Scope In As2
Im running into a scope issue with the below (only constructor shown)
Code:
function Excel() {
//constructor
trace("Excel Importer built");
this.swapDepths(5);
this.state = "in";
this.bttnClose.onPress = function() {
if (_parent.state == "in") {
var myTween = new Tween(_parent, "_x", mx.transitions.easing.Regular.easeOut, -626.5, 0, 1, true);
} else {
var myTween = new Tween(_parent, "_x", mx.transitions.easing.Regular.easeOut, 0, -626.5, 1, true);
}
this.enabled = false;
//trace("myTween "+myTween);
myTween.onMotionFinished = function() {
trace("state "+state);
if (_parent.state == "out") {
_parent.state = "in";
_parent.bttnClose.enabled = true;
} else {
_parent.state = "out";
_parent.bttnClose.enabled = true;
}
};
};
}
the tween onMotionFinished seems to have its own scope and i cant refer to find out what "state" is
is this a delegate.create thing ?
thanks
Scope:help
Hi everyone,
I'm a bit of a newbie to flash, and i'm not sure-how do u ensure that your variables are scoped locally to a scene only, and does not exist for all scenes?
-Nsmarina
The Scope Of This In AS3
Hi
I am just trying to understand the scope of this in AS3 for example in AS2
basicM_btn.onRelease = function() {
this._visible = false;
}
Would have made the button invisible
In AS3 I was expecting to write the same thing as this
function clickHandler(event:MouseEvent):void {
this.visible = false;
}
menuA_btn.addEventListener(MouseEvent.CLICK, clickHandler);
However this sets all of the content on the stage to visible = false
Is there a difference in the way that this works in AS3
Thanks for your help
Scope
Hi guys
I am developing a mobile application for the new Nokia N95 but i am having some problems. This is Flash Lite 2.0 by the way.
I want to use the softkeys to unload movieclips so that i can go back.
I have for instance, 2 classes
This is my infoClass. As you can see i am sending a _root.container_mc to my softKeyClass's constructor. This is all good and works fine.
PHP Code:
class infoClass extends MovieClip { private var container_mc:MovieClip; public function infoClass() { softKeys(); trace("constructor is running"); } public function softKeys() { var mySoftKey:softKeyClass = new softKeyClass(_root.container_mc); } }
But, then i wants put that into my softkeys and this is where it goes bad. I know that i am out of my scope becuase i am in the object.
PHP Code:
class softKeyClass extends MovieClip { private var _target_mc:MovieClip; private var test_btn:Button; private var info_mc:MovieClip; public function softKeyClass(target_mc:MovieClip) { _target_mc = target_mc; trace(target_mc +" target_mc"); trace(_target_mc + " _target_mc"); fscommand2 ("SetSoftKeys", "quit", "send"); fscommand2 ("FullScreen", true); var myListener:Object = new Object (); myListener.onKeyDown = function () { if (Key.getCode () == ExtendedKey.SOFT1) { // Handle left soft keypress event. //_root.target_mc.unloadMovie(); trace("left soft key"); } else if (Key.getCode () == ExtendedKey.SOFT2) { // Handle right soft keypress event. _target_mc.unloadMovie(); trace("right soft key"); } } Key.addListener (myListener); }}
I thought to my self, why not use the delegate class, but i cant get it to work. Is there anyone who can help me out?
This is what i tried with the delegate class.
PHP Code:
import mx.utils.Delegate;class softKeyClass extends MovieClip { private var _target_mc:MovieClip; private var test_btn:Button; private var info_mc:MovieClip; public function softKeyClass(target_mc:MovieClip) { _target_mc = target_mc; trace(target_mc +" target_mc"); trace(_target_mc + " _target_mc"); fscommand2 ("SetSoftKeys", "quit", "send"); fscommand2 ("FullScreen", true); //Key.addListener(Delegate.create("onKeydown", this, getKey)); var myListener:Object = new Object (); myListener.onKeyDown = Delegate.create(this, getKey); } private function getKey() { if (Key.getCode () == ExtendedKey.SOFT1) { // Handle left soft keypress event. //_root.target_mc.unloadMovie(); trace("left soft key"); } else if (Key.getCode () == ExtendedKey.SOFT2) { // Handle right soft keypress event. _target_mc.unloadMovie(); trace(_class._target_mc + " med parent"); trace("right soft key"); } Key.addListener (myListener); }}
I am sorry for my bad English, i hope you guys understand what i am trying to do.
/Morten
Scope When Using New
i'm not sure how scope works in actionscript - am i doing something wrong in the code below?
the loop runs 3 times, so there should be 3 movieclip loader objects and 3 listeners. but in the output, there is only 1 "loaded" trace. i.e. only one of the listener objects has called the onLoadInit function.
any advice appreciated!
CODEtrace("length "+content_xml.firstChild.childNodes.length);
for (var i = 0; i < content_xml.firstChild.childNodes.length; i++) {
var lo = new Object();
var mcl = new MovieClipLoader();
createEmptyMovieClip("floorplan"+i, this.getNextHighestDepth());
mcl.addListener(new Object());
lo.onLoadInit = function() {
trace("loaded");
floorplans[i]._width = floorplanWidth;
floorplans[i]._height = floorplanHeight;
floorplans[i]._x = offStageRight;
floorplans[i]._y = floorplanY;
};
trace("loading "+content_xml.firstChild.childNodes[i].attributes.image);
mcl.loadClip(content_xml.firstChild.childNodes[i].attributes.image, eval("floorplan"+i));
}
Scope Of Variables
Hey, Flash maniacs!
In all the books that I'm reading it says that a variable is scoped to its timeline, but they all talk about the root timeline as one timeline. What if there are 2 or more scenes in my movie? If I initialize the variables in scene one, can I still use their values in the other scenes or since these are different timelines I have to reassign values to them?
Thanks for enlightening me whenever I need it! This is a great forum!
Have fun!
Functions: What Is Their Scope?
If I write my own function, what is it's scope?
Say if it's in the main timeline...
Or if it's in a movie in a movie that is onw the main time line...?
What is it's scope?
Any help would be appreciated.
Thanks.
Nav
Scope Issues - Please Help
I am following along with O'reilly's Actionscript, the definitive guide, and having trouble with very basic scope problems I'm sure someone can help me with. On frame 1 of my main timeline I have the code :
trace (square.x);
trace (circle.y);
and I also have instances [named square and circle] of 2 symbols on this frame. On each symbols main timeline [frame 1] I have this code:
var y;
y = 4;
and
var x;
x = 3;
And for some reason that the book doesn't explain this wont work. It prints out blank, like my dot syntax is wrong or something. However when I move the code on frame one of the main timeline to frame 2 it works. Why is this and how can I fix it?
Thanks a lot!
Jeremy
Programming Art
http://www.programmingart.com
Scope And Rotation
Ok I have tried two other threads and no one can answer this for me maybe it is so hard I don't know but its bugging me out I can do it in flash 5 code but I wanted to get used to flashMX code so I tried this but it just isn't working. I have got the dots to attach and space out right but I wanted each of them to have a rotational value according to the mouse. But I think I have the scope all wrong can anyone please help
Code:
clipDistance = 40;
xRow = 6;
yRow = 3;
total = xRow*yRow;
for (i=0; i<xRow; i++) {
for (j=0; j<yRow; j++) {
movieNum++;
tempClip = _root.attachMovie("dot", "dot"+i+j, movieNum);
tempClip._x = 200+(clipDistance*j);
tempClip._y = 100+(clipDistance*i);
}
}
with (tempclip) {
tempclip.onEnterFrame = function() {
this.rot = (Math.atan2(_root._ymouse-tempclip._y, _root._xmouse-tempclip._x)/Math.PI)*180;
_root.dot._rotation = this.rot;
};
}
Function Scope
I have defined a function the first frame of my timeline but components inside MC's are not picking it up. Any idea's? Do I have to have my function in the first scene?
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
Scope Issue
if i create an onLoad function for an MC in it's parent MC and call a function in the onLoad that exists in the child, how do I reference that funciton...here's the set up
two MC's: A, B
in A I write:
//
function init() {
foo()
}
B.onLoad = init;
in B I write:
//
function foo() {
trace("init");
}
since foos is defined in B, should I call it like so B.foo or as is?
tx
Embedded MC Scope
How can you call an Object method from an embedded MC onEnterFrame Event. Its another problem with scope that i cant figure out
Code:
function newTarget()
{
this.MyClip=attachMovie( "fly", "fly1",100);
this.MyClip.onEnterFrame=function()
{
//'this' here refers to the MyClip Instance, i need to target its object parent
this.Update()
}
}
newTarget.prototype.Update=function()
{
trace("called")
}
newClip=new newTarget()
I've tried various different solutions and cant get it to work. Any help or pointers appreciated.
Cheers
Object Scope From MC
How can you call an Object method from an embedded MC onEnterFrame Event. Its another problem with scope that i cant figure out
Code:
function newTarget()
{
this.MyClip=attachMovie( "fly", "fly1",100);
this.MyClip.onEnterFrame=function()
{
//'this' here refers to the MyClip Instance, i need to target its object parent
this.Update()
}
}
newTarget.prototype.Update=function()
{
trace("called")
}
newClip=new newTarget()
I've tried various different solutions and cant get it to work. Any help or pointers appreciated.
Cheers
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)
GetTimer - > Scope
I am building a little pre-loader and I wish to use the getTimer() function. However, the file I am loading is loaded into a movie clip ("movieHolder") in my main movie which is the _root timeline. Please see the following code.
// Code in externally loaded movie
this.stop();
// preloading routine
this.onEnterFrame = function() {
fractionLoaded = this.getBytesLoaded()/this.getBytesTotal();
elapsedTime = (getTimer()-_root.movieHolder.startTimeDemo)/1000;
timeToLoad = elapsedTime/fractionLoaded;
timetoFinish = Math.ceil(timeToLoad-elapsedTime);
if(timetoFinish == "0") {
// move playhead to correct position
this.gotoAndPlay("demo");
}
};
_root.movieHolder.startTimeDemo = getTimer();
When I run the main movie, it picks up the "bytesLoaded" but does not trigger the timing function.
I have found that when I use the setInterval function, I can only get code to work if everything is referenced around the _root timeline. Is this a similar case / problem with getTimer() ?
I have tried some other referencing, but I am shooting in teh dark. Is there a definitive answer ?
Regards,
motorpilot
When Does TextHeight Come Into Scope?
I have code in a prototype defining a text field as so:
Code:
DraggerClip.createTextField("tf_draggerText", ++this.depthCounter, 0, 0, 0, 0);
DraggerClip.tf_draggerText._width = 160;
DraggerClip.tf_draggerText.multiline = true;
DraggerClip.tf_draggerText.wordWrap = true;
DraggerClip.tf_draggerText.autoSize = "left";
DraggerClip.tf_draggerText.html = true;
DraggerClip.tf_draggerText.leading = 0;
DraggerClip.tf_draggerText.htmlText = "<p align='center'>" + getDrag2Text()+ "</p>";
DraggerClip.tf_draggerText.embedFonts = true;
DraggerClip.tf_draggerText.setTextFormat(new TextFormat("Futura Md BT", 15));
DraggerClip.tf_draggerText._x = Drag2LeftMargin;
DraggerClip.tf_draggerText._y = DraggerClip.title_txt._y+DraggerClip.title_txt._height+50;
trace(DraggerClip.tf_draggerText.textHeight);
A couple problems...
It displays ok unless i comment out the autoSize. Then no text is rendered on the stage. I don't understand that behavior...i've tried with several different width values without any change.
But my main problem is returning the height of the text. I need to pull this value so I can play a clip that adjusts the background depending on how many lines the field wraps to.
I was under the impression that this value was immediately available...no need to let a frame or 2 elapse as we did in the days of Flash 5.
Object Scope Help
postObj = {};
postObj.me=this.postObj
postObj.page = 10;
postObj.lastPage=this.page/2
trace(postObj.lastpage)
how come it doesnt trace out the correct number. Is it got to do with scope? how do i solve this prob?
Rifle Scope Help
I am working on a site that uses the magnifying lense from this tutorial Real Time Magnifying Glass but I have altered it so that I have some t-shirts in the middle of a scope rather than the newspaper from the example tutorial. What I want to do is to make it so that once you aim the rifle over the shirt you want, and click the mouse, a larger example of the shirt shows up in the top right part of my flash window. Any help here would be appreciated. rifle.swf example<--copy link to clipboard, then paste in a new window for the link to work properly.
Path Or Scope?
Hi,
I have a very simple case to solve, but I can't figure out what's wrong. I guess that it has something to do with path or scope syntax.
Here's the scenario: I have 3 scenes (Scene 1, Scene 2 and Scene 3). Every scene has only 1 frame and a stop() instruction in frame 1.
My first example has a button in Scene 1 with the following script attached:
Quote:
on (release) { gotoAndPlay ("Scene 3",1); }
Things are working well, and as expected, when clicking it, the playhead jumps to first frame of Scene 3 and plays (in fact stops because I have a stop() there).
My second example, the one I can't solve, is slightly different. This time, in Scene 1, I have a movie clip and inside it there is my button with the same script attached. But this time the playhead doesn't jump where it was supposed to. Nothing happens.
So my questions are:
1. Why is that?
2. What is the correct syntax for the second case?
Thank you.
P.S. You can download these 2 examples from here:
working.fla and not_working.fla
Note: Macromedia Flash MX Professional 2004 needed.
Tracing Scope
hi.
i'm having some serious scope issues and want to know what the best way to troubleshoot this is.
i've traced as much as i can and couldn't figure it out, then i tried using targetPath() but that only works for finding movie clips and i'm looking for an array. any ideas?
thanks. fumeng.
Scope Within AS2 Classes
Hi,
See comment in class
Code:
class InstructionItem {
var mc:MovieClip;
var sndSound:Sound;
// CONSTRUCTOR
public function InstructionItem(clip,soundLinkageID):Void{
this.mc = clip;
this.mc.InstructionItem = this; // This is to be able to call the class methods from within this.mc.onEnterFrame haldlers for an example
this.sndSound = new Sound(this.mc._parent);
this.sndSound.attachSound(soundLinkageID);
}
// PUBLIC METHODS
public function playInstructions():Void{
this.sndSound.start();
this.sndSound.onSoundComplete = function(){
/*
I want to reach the class's methods & properties from here
like if I want the mc MovieCLip to play I would do maybe:
this.mc.play();
I know "this" refers to the Sound object so I can't do that. This
is a scope matter. But how to I do it then?
I suppose I could do the same as with mc - add a property to it
that I can then use within onEnterFrame and such to call the methods
but I have not been able to do it for the Sound object.
I always thought it was "a wrong way" anyway.
Please help me :)
*/
};
}
}
A Scope Problem-- With Xml?
So the following function is called from a successful XML.onLoad:
code:
function parseXML() {
var nNumberOfMenuItems = xmlMenu.firstChild.firstChild;
trace(nNumberOfMenuItems); //correctly returns 7
for(i=0; i<nNumberOfMenuItems; i++) {
trace(nNumberOfMenuItems); //doesn't return anything
}
Now if I change the for loop to run while i<1 the trace action inside the loop will read, correctly, 7. Huh? If I change the for loop to
code:
for(i=0; i<=nNumberOfMenuItems; i++) {
I get stuck for a bit, until the computer terminates the loop, and the trace inside the loop reads 'undefined' about 315,000 times.
Since the XML Object is loaded I assume there is a scope problem. Can anyone see what I can't seem to?
Thank you,
Richard
XML Scope When Used In A Class
I'm building a event calendar, re-building in 2.0 actually. The first thing the constructor does is load an XML file. Then onLoad I fire off 3 functions. For some reason, nothing happens with an unqualified reference and I don't know what the scope of the function is.
This does not work.
code:
tempXML.onLoad = function(success){
trace("XML loaded!");
buildCalendar();
setDates();
leapYearCheck();
}
I don't understand why these both kinda work
code:
tempXML.onLoad = buildCalendar();//runs a trace and attachMovie within buildCalendar works
code:
tempXML.onLoad = buildCalendar;//runs a trace but attachMovie does not work
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
Class And Scope
G r e e t i n g s ~
If I use something like this in a seperate class.as file ...
//imagine a for loop here ...
this.attachMovie("d", "c"+i, depth);
this["c"+i]._x = xVar;
this["c"+i]._y = yVar;
I get nada in the movie. but ...
If I use the exact code on the timeline it works great. It seems I'm missing the point when using a seperate class file. On the timeline I'm declaring ...
import MyClass
myClass = new MyClass();
what do I need to do to get this to work from the class I'm bringing in ?
Question Of Scope
Hello,
I want to check and see if I declare a global variable in the first frame of my movie, then load other movies in a movie clip within that movie, will those movies know about and can they affect that global variable?
version: mx2004 publishing in flash 6
Thanks,
Wendy
Scope Trouble
Code:
item_bin = [];
Myfunction = function () {
var service = new WebService("A service");
serviceResultObj = service.FetchSomething(this);
service.onLoad = trace("Loading");
serviceResultObj.onResult = function(result) {
for (h = 0; h < result.length; h++) {
title = result[h].attributes.title;
var ob = {title:title};
item_bin.push(ob);
}
trace("VerzamelBin " + verzamel_bin); // Succes
_global.verzamel_bin = verzamel_bin;
};
};
Myfunction();
trace("Global_item_bin " + _global.item_bin); // No Succes
I need this object "item_bin" outside my function.
It has been told to me to use 'Array:concat()' to copy the object.
Can anyone help me with this?
TIA
Scope Problem
Code:
item_bin = [];
Myfunction = function () {
var service = new WebService("A service");
serviceResultObj = service.FetchSomething(this);
service.onLoad = trace("Loading");
serviceResultObj.onResult = function(result) {
for (h = 0; h < result.length; h++) {
title = result[h].attributes.title;
var ob = {title:title};
item_bin.push(ob);
}
trace("VerzamelBin " + verzamel_bin); // Succes
_global.verzamel_bin = verzamel_bin;
};
};
Myfunction();
trace("Global_item_bin " + _global.item_bin); // No Succes
I need this object "item_bin" outside my function.
It has been told to me to use 'Array:concat()' to copy the object.
Can anyone help me with this?
TIA
Functions And Scope
Hi,
I am new to writing and using useful functions in AS.
If I write a function in MovieClip_A, how can I call that function in a ChildMoveClip_B?
How do I declare functions that can be used through all my child movies?
Do I have to decalre a class?
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?
Is This A Scope Issue Or Something Else ?
Here is the setup:
On my timeline, I have a movie clip called item1_mc that contains a button. On the button inside this movie clip is the following code:
Code:
on (press)
{
_parent.itemDragged(_name);
}
on (release, releaseOutside)
{
_parent.itemDropped(_name);
}
On my timeline, I have a movie clip called target1_mc. On my timeline, I also have the following functions:
Code:
function itemDragged(itemClip)
{
//start drag of the itemClip in question
startDrag(itemClip, false);
}
function itemDropped(itemClip)
{
stopDrag();
//call checkDrop() function for current itemClip
checkDrop(itemClip);
}
function checkDrop(itemClip)
{
if (target1_mc.hitTest(itemClip))
{
trace("succesful drop");
}
}
WHY doesn't this work and trace succesful drop when I run my movie and drag and drop item1_mc onto target1_mc ???.
HOWEVER, it does work if I hard-code the checkDrop function like so:
Code:
function checkDrop(itemClip)
{
if (target1_mc.hitTest(item1_mc))
{
trace("succesful drop");
}
}
Can anyone please assist me here.
Thanks.
Problem With Scope
I've made this class to read a sort of complicated textfile. It's supposed to read
the file, parse it and return an array when the function lms() is called.
Problem is, the private variable I've decleared on the top is empty when I try to return it. Even though I try to fill the variable with data in the LoadVars.onData function
I guess it's on the for-loop it goes wrong.
Can anyone see what I'm doing wrong with this variable?
Code:
/*
* Class LMSReader.as
*
* This class reads LMS from file and returns LMS:Array
*/
class LMSReader{
private var __infoObj:Array;
//Contructor
public function LMSReader(inFile:String) {
var lms_arr:Array;
var j:Number;
var temp_arr:Array;
var temp_arr2:Array;
var lastUpdateTime:String;
var restplass:Array;
var dest:String;
var lv:LoadVars = new LoadVars();
lv._parent = this;
lv.onData = function(inString){
/* Split string and convert to array */
lms_arr = inString.split("
");
__infoObj = new Array();
/* For each element in array */
j=0;
for (var i:Number=1; i<lms_arr.length; i++){
temp_arr = lms_arr[0].split(": ");
lastUpdateTime = temp_arr[1];
_root.restplass = lms_arr[i].split(";");
temp_arr2 = restplass[1].split("/");
dest = restplass[2].trimWhite();
/* Hent kun restplass på 1 uke */
if (restplass[5] == null){
__infoObj[j] += restplass[0] + " " + dest + " ";
if (restplass[3] != ""){ __infoObj[j] += "fra " + restplass[3] + ",- "; }
if (restplass[4] == "endast flyg"){ __infoObj[j] += "(kun fly) "; }
if (restplass[5] != null){ __infoObj[j] += "2 uker fra " + restplass[5] + ",- "; }
if (restplass[6] == "endast flyg"){ __infoObj[j] += "(kun fly) "; }
j++;
trace(__infoObj[j]);
}
}
}
lv.load(inFile);
}
//Get method
public function get lms():Array {
//Return XML object containing all contents from XML file; inFile
return __infoObj;
}
}
Thanks
/Per-Henrik
Scope Question
Hello-
I have 3 nested movie clips. say movieA, movieB and movieC with movieC being the innermost clip. Inside movieC there is a button.
When the button is clicked I would like to call a function in my actions layer on the main timeline. I tried:
_root.myFunction();
which does not work. I was thinking does _root not always refer to the main timeline, is there a different syntax I could use?
Scope Question
I have the following code:
Code:
start();
function start():Void{
var someNumber:Number = 15;
}
_root.onEnterFrame = function():Void{
trace(someNumber); //this gives undefined which is fine and i understand
}
However what i dont understand is when i modify the code to :
Code:
start();
function start():Void{
someNumber = 15;
}
_root.onEnterFrame = function():Void{
trace(someNumber); // This actually gives the value 15 instead of undefined like i expected
}
Does anybody know why this is so? cheers in advance
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;
}
}
}
}
Get Scope Of Object
How is it possible for a Class to obtain the scope on which it was instantiated without passing a 'this' reference?
I need my Class to know whether it was instantiated on the root timeline or inside another MovieClip. Is this possible?
Vars In The Scope
hello I want to make a for loop that
will use a var in the object scope. EX..
so say I have five objects named item1 throw 5 and I want to change the visablity of all the objects with a for loop that uses a var in the scope it would look some thing like this.
for (i = 0; i < 5; i++) {
item = "_parent.item"+i;
item._visible = false;
};
now this will make a var named "item" though it will only try to change the visablity of item._visible = false; not _parent.item1._visible = false;
and this dont work _parent.item+i._visible = false; So how do I and a var in the scope?
What's Wrong? Maybe Scope?
Hi all, I wanted to know if someone could tell me what the problem is with my fla I have been trying to figre it out for a whole day now and it's driving me mad. I have attached my fla so you can have a look at it (called scrollContent)
Basically the fla sets up a scollpane and dynamically puts some content in it. When you click the content it hides the scrollpane and starts another function which loads the details page. On the details page I have a back button. I want this button to hide the detials page (or remove it) and unhide the scrollpane page.
Anyway the back button works when I just load this swf. The problem is that this fla is loaded into a main movie via a button. So we have main with a button "scrollConent" which loads scrollContent.swf into a blank movie. Everything works here apart from the back button and its driving me mad. When I press it the details page is removed but the scrollpane doesn't reappear.
Seem to have posted a lot recently so thanks for all your help everyone
For Loop Scope?
hi all got script which makes the alpha of a bunch of button (clips) 70% and adds rollover and out to make it 100% alpha and back to 70% accordingly.
now i wanted to have each button which activate another to play an animation. doesnt seem to want to work thou.
the line of code _root["clip_"+i].play() wont do as i think its told. ive seen this problem before and its bugging me why it aint working cause it doesnt make sense. each button has its own animation. but when i trace _root["clip_"+i] it keeps coming back as 15 meaning its assigning the same value for each button does this make sense?
Code:
for (var i = 0; i<15; i++) {
_root["building_"+i]["picture_"+i]._alpha = 70;
_root["building_"+i]["picture_"+i].onRollOver = function () {
this._alpha = 100;
_root["clip_"+i].play()
}
_root["building_"+i]["picture_"+i].onRollOut = function () {
this._alpha = 70;
}
}
[F8] Scope Issues.
Ill try to make this not so complicated.....
But here i go
im having troubles with linking some buttons on my website.
I have it set up like so
1 main.swf file consisting of the entire website (excluding gallery page)
1 gallery.swf consisting of the gallery pics
I load the gallery.swf into the main.swf when someone clicks "gallery"
in the gallery.swf i have a MovieClip of about 30 buttons, called buttons_mc
and im trying to link those to the larger thumbnails i have setup later on in the timeline in "gallery.swf"
here is the code i have setup for the buttons
Code:
stop ();
this.onEnterFrame = function(){
if(rewind == true){
prevFrame();
}
}
this.onRollOver = function(){
rewind = false;
play();
}
this.onRollOut = function(){
rewind = true;
}
this.onRelease = function(){
_root.gotoAndStop(12);
}
now when i click on that button, it will goto frame 12 on the main.swf timeline, and not the gallery.swf timeline
ive also tried using this
Code:
stop ();
this.onEnterFrame = function(){
if(rewind == true){
prevFrame();
}
}
this.onRollOver = function(){
rewind = false;
play();
}
this.onRollOut = function(){
rewind = true;
}
this.onRelease = function(){
_parent.gotoAndStop(11);
}
that code ends up resulting in no action at all
i also have a scroll bar code which wont work when its loaded into the main.swf
it will work when i preview the the movie in itself
but not when i load it into the main.swf
here is that code
Code:
// Define the Scroll Area
top = _root.movMask._y;
bottom = _root.movMask._y+_root.movMask._height-_root.movScroller._height;
left = _root.movMask._x;
right = _root.movMask._x+_root.movMask._width;
// Bring all objects to the Scroll Area
_root.movIn._y = top;
_root.movIn._x = left;
_root.movScroller._y = top;
_root.movScroller._x = right;
// When the Scroller is Dragged
_root.movScroller.onMouseDown = function() {
if (hitTest(_root._xmouse, _root._ymouse)) {
startDrag("_root.movScroller", false, right, top, right, bottom);
}
};
// when the Scroller is Released
_root.movScroller.onMouseUp = function() {
stopDrag();
};
// Update Position every 10 milliseconds
setInterval(Update, 10);
function Update() {
var ratio = (_root.movIn._height-_root.movMask._height)/(_root.movMask._height-_root.movScroller._height);
_root.movIn._y = ((_root.movMask._y-_root.movScroller._y)*ratio)+_root.movMask._y;
}
i know this is just an issue of either taking out the "root" part and replacing it with something else
i just dont know what that something else is!
Thnx so much in advance!
OOP Function Scope?
Hello, I've have started doing some OOP programming in flash8 AS 2.0 but have ran into some problem, how do you call a function in the class if it looks like this?
Code:
class someClass {
var mc:MovieClip;
public function someClass(mc:MovieClip)
{
this.mc = mc;
this.mc.onPress = function()
{
testFunction(); // <--- here!
}
public function testFunction()
{
trace("Yes!, I was called!"); // <- Call this!
}
}
}
Maybe it is totally wrong to do like this or it is something ive missed,
I would be happy if someone could guide me to the right way of doing it!
Thanks
|