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




Declaring Public Variables



I want to declare a public variable, which its value is saved every time I am using it in a function.Please explain to me how to declare it and where. I want to use the variable inside a movie clip for an openning menu. The problem is that I have a few categories and I want each time I press on some item in the menu that the open menu of this item would be opened, and the previous menu of the other item would be closed.Thank you,Avishay.



KirupaForum > Flash > Flash 8 (and earlier)
Posted on: 03-29-2007, 12:16 PM


View Complete Forum Thread with Replies

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

Declaring Variables
hi,

Does flash assign default values to variables if not declared previously? Like in the sample below

onClipEvent (mouseMove) {
n++;
if (n == 5) {
i++;
duplicateMovieClip (_root.effect, i, i);
setProperty ("/" add i, _x, _root._xmouse);
setProperty ("/" add i, _y, _root._ymouse);
n=0;
}
}

the variables "n" and "i" were not defined previously.

Declaring Variables
Im trying to set a "global" variable that gets its value from a mc that contains a dynamic text field. I cant see to get it working..

I need to be able to pass this onto a new scene..

Just one other thing.. do i reference this new variable in the new scene as _root.variable-name?

Skek

Declaring Variables
Hi, I'm a newbie. Im trying to set up a shopping cart. I have set up a series of dynamic text fields to add items to each time a product's Add to SC is pressed. What I want to do is add a counter each time another item is added so I can specify which field to place next item in.

1/ Where would I declare my counter variable, it must be seen by all Add to SC buttons throughout catlogue.

2/Can I concatenate variable names ie where item = item and counter = 1 - will item + counter = item1

Declaring Variables
Hi,
I am creating a full flash site and want to create a variable which will store which section/page the user is on. What code would I use to set the variable to something like "Home" and then what code do I need to insert in my buttons changing that value when they navigate to another section.

Thanks

Declaring Variables
flash mx

is there any way i can declare variables using loop or something, instead of declaring each and every one individually

like how can i declare 50 variables in a short way instead of:

var v1, v2, v3, v4, v5.... v50;

is there any other way that is easier and shorter???

Declaring Variables
Long story short, I have one .swf.
In that .swf I have a movie clip.
In that movie clip I have a FOR loop.
In the entire .swf I have a movie clip that is in the library and is able to be exported for actionscripting.
In the FOR loop I attach the movie from the library.
So now we understand that the attached movie is NOT a seperate swf file. It is all in one .swf file.
In the FOR loop, I want to pass along a variable to the attached movie clip.

How do I do that without using _global variables?


In detail, this is the loop and the problem i'm having.

for (_global.count=1; _global.count<=sectionTotal; _global.count++) {
this.attachMovie("Small_Loader", "small_loader"+_global.count, _global.count+10);
small_loader[_global.count].small_image_mc.loadMovie("fscommand/Images/medium/"+_global.portsection+""+_global.count+"medium.jpg ");
}

I want to pass along the current value of _global.count to the attached movie clip. The way I initially tried that was that within the attached movie clip I assumed that when it was loaded via this FOR loop, that the _global.count would not update and it would retain the value that was assigned to it when the movie clip was loaded. HOWEVER, I soon found out that the FOR loop had run so quickly, that by the time the 1st attached movie clip was loaded, the FOR loop had already run through the _global.count sectionTotal and had exited. So when the attached movie clips looked at the _global.count variable, it was always 1 higher than the sectionTotal variable.

What I want to happen is that let's say on the 1st iteration of the FOR loop, I want the current value of _global.count to be transferred to the 1st attached movie clip (Which happens to be "Small_Loader"). So when small loader runs, it will retain the value of 1 for _global.count. When the 2nd iteration of the loop happens, the 2nd attached movie clip will retain the value of _global.count = 2. So on and so forth. But like I said, the FOR loop happens so quickly that the _global.count never takes hold properly in the attached movie clips. How do I transfer the current _global.count variable from within the FOR loop, to the attached movie clip on any given iteration of the FOR loop?


---------
for (_global.count=1; _global.count<=sectionTotal; _global.count++) {
this.attachMovie("Small_Loader", "small_loader"+_global.count, _global.count+10);

small_loader[_global.count].small_image_mc.loadMovie("fscommand/Images/medium/"+_global.portsection+""+_global.count+"medium.jpg ");
}
---------

Declaring Variables [F8]
Have been doing some reading and everything I've come across says you don't have to declare a variable type in flash the way that you have to in other languages (dim x as integer etc.. etc...) but I've come across a tut. that has
var dir:Number = 1;
I understand that the "var" declares it as a local variable, does declaring it as a number conserve memory? and if something is declared as a number, would it generate a type mismatch error if somewhere along the line you tried to make Number="some text here"?
thanks heaps in advance

Help With Declaring Variables Using Var
hi guys

i'm having trouble writing variable names

I used to write something like this when joining some text and the contents of a variable:

_root["fruit_"+type] = "banana";

how can I write this with var before it?

e.g.

var ["fruit_"+type]:String = "banana";
doesn't work

many thanks

Declaring Variables
Im having a hard time trying to declare these variables:

ActionScript Code:
For(var i = 1....){
name+i = ...
link+i =...

I want it to create the variable name1, link1, name2, link2... and a lot more, so Im using a FOR to do that, but it tells me that something is wrong with the name+i part of the code, I assume I cant refer to a variable to be created with variable+another_variable = something.

How can I create these variables ??? Im sure its pretty simple, but I can't figure out. Thanks.

Declaring Variables In AS2
In converting from AS1 code to AS2, I don't know how to declare variables that are part of a set. eg I have a set of buttons and want to change the state of each button depending on the value of another variable. So I use the variable .assign for each of the buttons. How do I declare this type of variable?









Attach Code

Set the value:
_root.N1["button"+countst].assign = NavArray[i+2];
Check the value:
if(_root.N1["button"+countst].assign == 1)

Declaring Variables
Hi,
I am creating a full flash site and want to create a variable which will store which section/page the user is on. What code would I use to set the variable to something like "Home" and then what code do I need to insert in my buttons changing that value when they navigate to another section.

Thanks

Declaring Variables
What is the difference between declaring a variable like this:

variable = 1;

and declaring it like this:

var variable:Number = 1?

Why is it better to use the second way?

Public Variables? NEED SOME HELP Plz TNX
I want to make a (public) variable that i can use on many buttons (scripts) or movieclips. for example if(Number(test) == 0) .......
I want to check Number(test) somewhere else 2, in another script but the same scene.

TNX a lot

Public Variables In AS3...
I am converting a large application from AS2 to AS3, and I'm going mad. The thing I'm stuck with is visibility/accessibility of variables across packages. Following the basic recommendations, I split my program in packages and classes. The thing though is that I need a set of "global" variables to be accessible and modifyable by all of the packages. So suppose I have a package/classes A, B and C. A contains all the variables, declared as public. B and C need to modify the vars in A:

package {
public class A {
public const c1 = 99;
public var v1:number = 999;
}
}

package {
import A;
public class B {
public function B () {
var v:A = new A();
v.v1 = 222;
}
}
}

package {
import A;
public class C {
public function C () {
var v:A = new A();
trace (v.v1); // v.v1 is undefined!
}
}
}

v.v1 is undefined, that's of course because I instatiated another set of variables in package C, different from the one in B. On the other hand, if I don't instantiate, I cannot see the public variables defined in class A, in any other package.

Why?
What should I do to make this simple thing work?

Silvano

Declaring Variables.... I Forget How.
Hey ppl,

I think I used to know how to do this but since the work I am getting lately is so inconsistent, I think I forget how.

I need to pass a swf to a guy for use in Authorware.

He wants me to make a blue square, and a green square.
And when the variable = "blue" he wants the blue square to come up, when the variable = "green" then the green square needs to come up.

I have no idea if I should make this a 3 frame swf, with nothing in the first frame, and a blue square on frame 2, a green square on frame 3... etc. Or make it all a movie clip? I have no idea where or how to even begin.

Please help me, maybe once this is answered I can remember how to do other stuff too.

Thank you very much.

Declaring Variables *curiosity*
whats the difference between writting:
var When=0;

or

When=0;

or

set(when, 0)


???????


I see these 3 different types of declarations, but I cant tell the difference btw then
Help files didnt help me understanding it....

Declaring Variables Within A Loop
Hi im making a flv thumbnail preview gallery..this requires me to define a lot of netstream objects... not sure maybe my brain isnt working today but trying something like this


Code:
var noMovies:Number = 20;

for(var i:Number=0; i < noMovies; i++){
var _root["ns"+i]:NetStream = new NetStream(nc);
_root["ns"+i].setBufferTime(0.1);
}
however i get a syntax error expected '{' etc etc .. thanks in advance for your help!!

When And When Not To Use Var When Declaring Variables, And When To Datatype
Hello everyone, I'm a pretty uh...well, what's the level right above "noob" when it comes to Actionscript?

Well, whatever that is, I'm it! And there are a few things that I just don't quite get.

1. When and when not to use var when declaring variables.

var sometext = "blah";

vs.

sometext = "blah";

I see people use them on and off, sometimes they do sometimes they don't. What's the right method?

2. Datatyping. When to use it and when not to. From what I understand, if you datatype your variable Flash will sense that and offer relevant codehints and available functions while your typing. Like, say If I declare...

var listener:Object = new Object();

If I begin typing listener. flash will show a list of all the available functions and...constructors, whatever they're called. Is that all the datatyping does?

Well, uh, thanks! Those are my questions.

Best Practice: Declaring Variables
Hi all

Some flash manuals proscribe putting all your variables in a function and then running that function. something like

init();
function init():Void{
varX = 1;
varY = 2;
}

however if you want to strict datatype the variable you have to put it like so:
var counter:Number = 0;

if you do that in a function it will become local to the variable and will be destroyed as soon as the function finishes running. So what's a guy to do? Just declaring all your variables in the _root?

Dynamically Declaring Variables In AS3
Hi.

I'm trying to migrate from AS2 to AS3 and have stumbled on this. I can't find how to create dynamically referenced variables in AS3. Can anyone give me a hand? Thanks!

Here's the code I used in AS2:







Attach Code

//AS2
for (var i:Number = 0; i < 10; i++) {
this["myThing" + i] = new Object();
}

Declaring Variables With For Loops?
ActionScript Code:
function b0 () {    trace("different action 1");}function b1 () {    trace("different action 2");}for(i=0;i < 2; i++) {    ["b"+i+"()"];}
How would that be done? Sorry, I already knew how to declare vars, had the wrong question & wrong title but this is my actual question now.

*Nevermind, its solved .

Declaring Variables Through An If Statement
i'm kind of an actionscript noob
does this make any sense?

i'm trying to define a variable based on whether or not another variable is null.
(i created this example for the sake of clarity)



Code:
var nothing:String = null;
var apples:String = "Red";
var bananas:String = "Yellow";
var blueberries:String = "Blue";


if (nothing == null) {

var fruitSalad:String = "colorless";

} else {

var fruitSalad:String = apples + bananas + blueberries;

}


trace(fruitSalad);

i keep getting this as an error:
1151: A conflict exists with definition fruitSalad in namespace internal.

any help would rock

thanks guys | idriss

Dynamically Declaring Variables
I have a loadvars object that has a number of properties called member1, member2 etc. They need to be transferred to variables but since I don’t know how many memberN properties there will be for the Loadvars object I don’t know how many variables to declare.


ActionScript Code:
for (var g = 1; g<=num_members; g++) {
this["current_member"+g] = l_members["member"+g].split("¸");
}


The code to the right of the “=” sign works fine but not the code on the left.

My thinking when using “this["current_member"+g]” was to use array notation (like the old eval function) to reference a variable called current_memberN. But since I haven’t declared the variable it would create it since variables that are not explicitly declared come into existence when first used (or does that rule no longer apply with AS2?)

I tried it and it didn’t work.

So I tried using something like>

ActionScript Code:
Var ["current_member"+g]


But it created a syntax error so I can’t do that.

The only other way I can think of is to create an object and then use array notation to point to a property.

ActionScript Code:
var myobject:Object = new Object();
for (var g = 1; g<=num_members; g++) {
myobject["current_member"+g] = l_members["member"+g].split("¸");
}


But since the property called current_memberN does not exist yet I may still face the same problem as my first approach.

Any body have any ideas on how I could overcome this problem?

Declaring Variables In Loop
Hello, I am wondering how to declare a variable inside a event handler which will change it's name automatically. I want the name to increment after ever time a new instance is made. My Code is as follows:

Code:

function addLight(E:TimerEvent) {
var 'l' + num:Light = new Light();
num++;
}



where num is a variable set at 0 so i would like there to be instances of this object like l0, l1, l2, l3.
Any ideas anyone as to how i can solve this problem? Thanks

Declaring Variables - Probably An EASY Question
How do you declare variables in Flash.

I want to set a variable that = true when the panel is up
and that = false when the panel is down.

I've tried but with no success.

Here's my site if you want to see what I'm talking about.

- Matt

Declaring _global Variables And Functions
I'm using Flash MX 2004 Professional.
I have an application consisting of a main.fla which houses some _global variables as well as a _global function. I guess I was under the impression that those variables and functions that I've declared _global were accessable to all timelines. I'm loading an swf at _level100 which will access the _global vars and functions on the _level0 timeline. So far I haven't had any luck retrieving those things declared _global(at _level0) from _level100. Any suggestions?

Declaring Variables For Dynamic Text Box
Hello,

I am trying to declare variables to be displayed in a dynamic text box, but for some reason it isnt working, even though i have done this 100 times before

On first frame is this code

green_11.text = "Insurance Industry Knowledge";
green_12.text = "92%";
green_13.text = "82%";
green_14.text = "96%";
green_15.text = "72%";
trace("green_11 - " + green_11);

later in the time line, inside a movie clip i have a dynamic text box with an instance name of green_11 it wont display..

my trace wont display either... it will if i remove the .text, but the text box still wont work

Declaring New Variables In A Movie Clip
i have just started to learn AS3 but i am confused on one issue, in the tutorials i have done its says that you have to declare new variables with var and declare there data type so it looks like this:


Code:
var testVar:String = "hello";
but what if you want to do things properly declare a new variable in a new movie clip? the following code works but its it "correct"?


Code:
var newClip:MovieClip = new MovieClip();
addChild(newClip);
newClip.testVar = 4;
trace(newClip.testVar);

Declaring Multiple Variables Simultaneously. Possible?
Just wondering if any take on this notation:

var1, var2, var3 = var_content;

works in Flash? I cannot seem to make it work myself. Am I doing something wrong?

Thanks

Use Your Private And Public Variables Wisely T_T
An issue that has caused me 2 weeks worth of problems turned out to be a simple one.

I had code such as this

code:
// ini vars
someArray = new Array();
totalArray = new Array()


function one(){
while(someArray.length > 0){
someArray.pop();
}

// someArray is given values //

someObject = new Object();
someObject.holdingArray = someArray;

totalArray.push(someArray);
}

function two(){
while(someArray.length > 0){
someArray.pop();
}

// someArray is given DIFFERENT values //
someObject = new Object();
someObject.holdingArray = someArray;

totalArray.push(someArray);
}


sorry for the terrible fake code, but what was happening was totalArray.holdingArray[0] and totalArray.holdingArray[1] would be the same values causing all sorts of crap. basically holdingArray[x] was one away from the values it should have been.

What fixed it?

code:
// ini vars

totalArray = new Array()


function one(){
someArray = new Array();

// someArray is given values //

someObject = new Object();
someObject.holdingArray = someArray;

totalArray.push(someArray);
}

function two(){
someArray = new Array();

// someArray is given DIFFERENT values //
someObject = new Object();
someObject.holdingArray = someArray;

totalArray.push(someArray);
}



using private variables fixed it... may seem simple here, but on a 500 line program that is working... almost perfectally it was the last place i looked.

Well hopefuly this helps some one but I just wanted to vent my frustration over such a stupid problem that has held me up. Well at least I learned something

Accessing Other Classes Public Variables?
Hi all,

Is it possible to access another classes public variables without using a function?

thanks

Gareth

Using Value Variables Throw Public Functions
He all!!

I'm trying to use value variables throw public functions in the same class.
Is there any possible to do it?

I'll explain:

Imagine we have a class name Mp3Player that plays some mp3 file and get is ID3 songName:
In that class we have the package:

Quote:




package Mp3Player{

import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.ID3Info;
import flash.net.URLRequest;
import flash.events.Event;

public class Mp3Player {

private var sound:Sound;
private var req:URLRequest;
private var context:SoundLoaderContext;
private var channel:SoundChannel;
private var id3:ID3Info;
private var nomeMusica:String;




Then we have the public class to load and play the mp3 file passed using argument "file":

Quote:




public function tocarMusica(file) {
sound=new Sound ;
req=new URLRequest(file);
context=new SoundLoaderContext(8000,true);
sound.load(req,context);
channel=sound.play();
sound.addEventListener(Event.ID3,setNome);
}




After we load and start play the mp3 file, we whant to get the ID3 songName and save it in the "nomeMusica" variable:

Quote:




public function setNome(event:Event) {
id3=event.target.id3;
nomeMusica=id3.songName;
trace("Nome: "+nomeMusica);
}




Now the problem is...How can i trace(nomeMusica) outside the "public function setNome(event:Event)"?

Or in other words:
In the FLA file i can call to play the mp3 file like this:

Quote:




var musica = new Mp3Player();
musica.tocarMusica("song.mp3");




And how can i call the ID3 songName using sometinh like:

Quote:




musica.getName();




Sorry my english and i hope you can help me in a simple way.

Using Value Variables Throw Public Functions
He all!!

I'm trying to use value variables throw public functions in the same class.
Is there any possible to do it?

I'll explain:

What i whant is in tha FLA file to get the songName of the mp3 like trace(musica.nomeMusica);
quote://AS Code
package Mp3Player{

import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
import flash.media.ID3Info;
import flash.net.URLRequest;
import flash.events.Event;

public class Mp3Player {

private var sound:Sound;
private var req:URLRequest;
private var context:SoundLoaderContext;
private var channel:SoundChannel;
private var id3:ID3Info;
private var nomeMusica:String;

public function tocarMusica(file) {
sound=new Sound ;
req=new URLRequest(file);
context=new SoundLoaderContext(8000,true);
sound.load(req,context);
channel=sound.play();
trace("A tocar");
sound.addEventListener(Event.ID3,id3Info);
}

public function id3Info(event:Event):void {
id3=event.target.id3;
nomeMusica=id3.songName;
}
public function get getNome():String {
return nomeMusica;
}
}

//FLA Code
import Mp3Player.Mp3Player;

var musica:Mp3Player = new Mp3Player();
var nome:String = musica.getNome;

musica.tocarMusica("Saia_Indiscreta.mp3");
trace(nome);
}
The trace of my code is:
quote:A tocar
Null
What i'm doing wrong or is missing?

Creating Public Or Global Variables
I would like to read/write/change variables from anywhere in my movie. I found an article that I thought would answer my question, but I'm unable to get it to work (see here: http://greenethumb.com/article/11/global-variables-in-as3).

I created a file called GlobalVars.as
Code:

package com.Creative.ui
{   
   public class GlobalVarContainer
   {
      public static var vars:Object = [];
      vars.PageTotal = 1;
   }
}

I want to access the PageTotal variable from my DocumentClass.as
Code:

package com.Creative
{
        import ui.GlobalVars.GlobalVarContainer.*;

        public class DocumentClass extends MovieClip {
      
      public function DocumentClass ():void {
         trace("Page Totals: " + GlobalVarContainer.vars.PageTotal);
                }
        }
}


But I'm getting the following error in my output window.
ReferenceError: Error #1065: Variable GlobalVarContainer is not defined.
at com.Creative::DocumentClass()

Creating Dynamic Class Variables Without Declaring Them First
Is it possible in AS 2.0 to dynamically create class variables without declaring them first?

I know you can do:
code:
class MyClass
{
function MyClass()
{
this["foo"] = "bar";
}
}

var MyObject = new MyClass()
trace(MyObject["foo"]);

But can you do something like:
code:
class MyClass
{
function MyClass()
{
this.variables["foo"] = "bar";

//Or

this.addVariabele("foo") = "bar";
}
}

var MyObject = new MyClass()
trace(MyObject.foo);

?

Declaring Variables And Calling Function From Timeline
I could use some help figuring out how to convert some older script to AS 3. I'll start simple - here is the main class and a bit of code on the main timeline that calls it. I'm not certain how to declare the "settings" variable in AS 3 style. And I'm not sure how to call the "QuickCheck" public function from the main timeline.


Code:
package {

import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.StageDisplayState;
import flash.accessibility.AccessibilityProperties;
import flash.text.TextField;
import flash.text.TextLineMetrics;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
//----------------------------------------------------------------
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
//----------------------------------------------------------------

public class QuickCheck extends MovieClip {

//CUSTOMIZE//////////////////////////////////////////////////////////
var settings = new Object();
//correct color
settings.correctColor = "#85BB3D";
//incorrect color
settings.incorrectColor = "#CF7E05";
//weather feedback is shown or not
settings.hasFeedback = true;
//prefix for the answer choices
settings.choiceLetter = "A,B,C,D,E,F,G,H,I,J";
//space between the questions and answer chocies
settings.questionChoiceBuffer = 14;
//space between the answer choices
settings.choiceBuffer = 14;
//CONSTRUCTOR FUNCTION///////////////////////////////////////////////
public function QuickCheck(path, questionArr, directionsArr):void {
//reference to path
this.path = path;
this.questionArr = questionArr;
this.directionsArr = directionsArr;
this.currentQues = 0;
this.totalQues = questionArr.length;
this.currentAnswer;
this.submitOpen = false;
//trace("CONSTRUCTOR FUNCTION EXECUTED****************************");
}
/////////////////////////////////////////////////////////////////////
private function init(settings):void {
this.correctColor = settings.correctColor;
this.incorrectColor = settings.incorrectColor;
this.hasFeedback = settings.hasFeedback;
this.choiceLetter = settings.choiceLetter.split(",");
this.questionChoiceBuffer = settings.questionChoiceBuffer;
this.choiceBuffer = settings.choiceBuffer;
//trace("init() called");
}
}

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

On Frame 18 of the main timeline (this is AS1.0/2.0 style script):

var activity = new QuickCheck(this, questionArr, directionsArr);
activity.init(settings);

Declaring A Long List Of Variables With The Same Default Value.
How can I do this in a way that looks pretty and doesn't take up too many lines of code?

Here's what I want to improve upon:
var name1 = "default value"
var name2 = "default value"
var name3 = "default value"
var name4 = "default value"

I want to do something cleaner like this:
var name1, name2, name3, name4 = "default value"
But that is not correct syntax.

Any ideas?

Problem Declaring Functions/variables In Blank Movieclip
I'm attempting to declare functions and variables inside of a blank movieclip so that when the clip is duplicated, each instance of the clip will have these properties, however, I'm having some issues which I think relate to scope which I can not figure out.

To keep things simple, I can do this in the main timeline...


Code:
_root.movieclipname._BLAH = "testing";
and when attempting to reference this newly created variable, there are no problems...

However, if I attempt to create the variable inside of the movie clip actionscript, I am unable to access it outside of the clip. For example..


Code:
// inside of the movie clip

this._BLAH = "testing";
this returns an undefined value when attempting to reference it outside of the clip, which leads me to believe it's possibly a scope issue.


Code:
// main timeline
trace( _root.movieclipname._BLAH );
// returns undefined when setting inside of movieclip
I've heard of prototyping but i'm not sure exactly how to employ this in my example. any help would be greatly appreciated.

-Ryan

Does Declaring Variables In An OnEnterFrame Handler Affect Speed?
Hi there,

I'm changing the color af about 50 movieclips, every frame (part of a fogging routine for a 3D engine). It seems obvious to first assign a color object to each clip and then upate it's transform on each frame, but I wondered if there would be a significant speed / memory hit with declaring a new local Color object inside the function on each execution of each frame?

Obviously I can run tests, but I wondered if anyone had thoughts.

Thanks,
Dave

Problem Declaring Functions/variables In Blank Movieclip
I'm attempting to declare functions and variables inside of a blank movieclip so that when the clip is duplicated, each instance of the clip will have these properties, however, I'm having some issues which I think relate to scope which I can not figure out.

To keep things simple, I can do this in the main timeline...


Code:
_root.movieclipname._BLAH = "testing";
and when attempting to reference this newly created variable, there are no problems...

However, if I attempt to create the variable inside of the movie clip actionscript, I am unable to access it outside of the clip. For example..


Code:
// inside of the movie clip

this._BLAH = "testing";
this returns an undefined value when attempting to reference it outside of the clip, which leads me to believe it's possibly a scope issue.


Code:
// main timeline
trace( _root.movieclipname._BLAH );
// returns undefined when setting inside of movieclip
I've heard of prototyping but i'm not sure exactly how to employ this in my example. any help would be greatly appreciated.

-Ryan

Declaring A Tie.
Code:
if (teamA>teamB) {
gotoAndPlay("teamA_wins", 1);
//playerOne wins
} else {
gotoAndPlay("teamB_wins", 1);
//playerTwo wins
}
this is the code i am using if i wanted to add in the effect of a tie, what would the code be for that. i am thinking it might be


Code:
if (teamA>teamB) {
gotoAndPlay("teamA_wins", 1);
//playerOne wins
if(teamA=teamB){
gotoAndPlay("tie", 1);
//teams tie
} else {
gotoAndPlay("teamB_wins", 1);
//playerTwo wins
}
but i am not for sure that this is the answer, so if someone could look at it i would be very thank you

Declaring A Function
I'm interested in finding out whether there is ANY difference to declaring a function as:

Code:
function myFunction() {};
or by using a variable

Code:
myFunction = function() {};
I know they both WORK the same, but is using the variable actually adding any extra overhead to your movie? Looking in the Debugger, the results for both look identical.

Any definitive reason why one is better than the other? Thanks.

Declaring Constants
How do you declare a constant in Flash MX? For example, I need a constant integer.

In java this is done by:
final int name;
In C++ this is done by:
const int;

How can I do something like this in Flash?

Declaring Functions On The Fly...
Hi.

I am using duplicateMovieClip to create a number of movie clips that must each have their .onRollOver and .onRollOut behaviours.

The number of clips that I will be creating will be drawn from an xml file, and so the names of the clips cannot be hardcoded because I do not know how many there will be.

Can I write some kind of universal function to handle the onRollOver and onRollOut methods for all. Note: I must be able to capture the _name of whichever clip is being used.

If I have been unclear, just ask and I'll clarify.

Many thanks in advance,
Adam

Declaring Arrays
In actionscript is there a way to do something like this...

var myVar = 5;

var myArray[myVar][3];

var myOtherArray[myVar][myVar];

Basically I want to use a variable to declare a multidemsional array, is this possible?

Declaring Vars
Hi guys!

Well i use flash to animate stuff and i dont know much of actionscript.

My question is:

imagine i have 3 menus. each time u click in one he makes a moove and go to a diferent place.

The problem is how do i tell the movie that if i click the 3rd menu, and the 2nd one is up i want the 3rd to go back?

i know that is something like:

if menu3 == 1{
gotoandPlay (10)

but my answer is: how the hell i tell to a movie that his state is 1 or 0?

[F8] Declaring Integers?
just a quick question..
how to declare integers?
I've always used
var counter = 0;

and that worked,

i saw an int in actionscripting

but doesnt it work like in VB?

int counter = 0; ?

Declaring A Variable?
If I draw a dynamic text field on the stage and give it a name in the Var field within the Properties panel is that essentially declaring a variable?

Puke

Problems Declaring Var...
function cycleLoad works... it attaches 6 movie clips to the stage in a circle.. which is what i want.. im having troubles declaring the
var theMovie:MovieClip = _level0.container_mc_["item" + i];

when i trace the icon when its click.. it outputs 6 undefined, when i want the name of the clip and the container clip..

basically, when the user rolls over one of the six icons, the icon zooms up with the tween class, then function out(), zooms back to _x,_y positions..


heres my code...

var radiusX:Number = 180;//width radius of cycle for the animated icons
var radiusY:Number = 150;//height radius of cycle for the animated icons
var centerX:Number = 250;//X center of cycle
var centerY:Number = 210;//Y center of cycle
var cycleRotate:Number = 300.03;
//var home:MovieClip = this;
var arrowCenterX:Number = 110;
var arrowCenterY:Number = 80;
var arrowRadiusX:Number = 0;
var arrowRadiusY:Number = 0;
var menuIconsArray:Array = new Array("healthySkin", "environMoist", "lowerSkin", "drySkin", "waterInfusion", "healthyCellular");

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

cycleLoad();

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

function over(){//show movie clip icon and follow around cycle{
for (var i:Number = 0; i < menuIconsArray.length; i++) {
trace(_level0.container_mc_["item" + i]);
var theMovie:MovieClip = _level0.container_mc_["item" + i];//reference to the item/icon in the cycle
//var emptyClip:MovieClip =

theMovie.xPos = theMovie._x;//store current x position
theMovie.yPos = theMovie._y;//store current y position
theMovie.theScale = theMovie._xscale;//store scale
if (theMovie = this._parent) {//icons that weren't click do the if
var tw:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,theMovie._ xscale,120,0.5,true);//new Tween(which item to animate, which property to animate, type of easing, start value, end value, time, true = seconds);
var tw2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,theMovie._ yscale,120,0.5,true);
var tw3:Tween = new Tween(theMovie,"_x",Strong.easeOut,theMovie.x,theM ovie.xPos,0.5,true);
var tw4:Tween = new Tween(theMovie,"_y",Strong.easeOut,theMovie._y,thM ovie.yPos,0.5,true);

}
}
}

function out() {
for (var i:Number=0; i < menuIconsArray.length; i++) {
var theMovie:MovieClip = _level0["item" + i];//reference to the item/icon in the cycle
theMovie.xPos = theMovie._x;//store current x position
theMovie.yPos = theMovie._y;//store current y position
theMovie.theScale = theMovie._xscale;//store scale
if (theMovie = this._parent) {//icons that weren't click do the if
var tw:Tween = new Tween(theMovie,"_xscale",Strong.easeOut,theMovie._ xscale,100,0.5,true);//new Tween(which item to animate, which property to animate, type of easing, start value, end value, time, true = seconds);
var tw2:Tween = new Tween(theMovie,"_yscale",Strong.easeOut,theMovie._ yscale,100,0.5,true);
}
}
}

thanks..

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