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




To Declare, Or Not To Declare?



I'm not quite sure what to call these, so I'll start off with examples.

Math and stage

You can type Math.cos(blah), for example, and it works.
or type stage.focus = blah; ...and that works.

YOU'VE NEVER DECLARED THESE!

I've searched Google and a couple forums for a few days. (I'm shy about posting on forums, and try to avoid it as much as possible.) But I have not found anything. Perhaps, it is due to the fact that I don't know what exactly to be searching for.

My main question is this:
How do I create my own custom class that needs no declared instances, like math and stage. Is it possible?

Thanks.



FlashKit > Flash Help > Actionscript 3.0
Posted on: 08-15-2008, 06:00 PM


View Complete Forum Thread with Replies

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

[F8] How Do I Declare?
A multidimensional array using good coding practice? I know the below works but I dont like it:


Code:
var testing:Array = new Array();
testing[0] = new Array();
Id like to use something like var testing[0]:Array = new Array(); but it doesnt work.....

Declare Variables?__|
sorry, i posted this in the wrong forum!

do i need to declare variables in my flash movie after i have loaded them from an asp page?
i have a text box that displays the variable value on the stage but i have an if/then statement that should perform a function that does not work based on the variable value...

and btw...i actually do answer other posts in this forum but i have been very busy lately.

Why Can't I Declare A Variable...?
Hi, i'm having a nightmare with a flash file...

i have a form with a variety of text boxes, ComboBoxes, CheckBoxes etc. They're all named correctly.

the submit button on the form is calling a function on the main timeline in the same keyframe as the submit button called sendForm()

here is the code in sendForm()



Code:
function sendForm()
{

var result_lv:LoadVars = new LoadVars();

result_lv.onLoad = function(success:Boolean) {
if (success) {
_root.gotoAndStop("submitted");
} else {
_root.gotoAndStop("submitted");
}
};

var send_lv:LoadVars = new LoadVars();

send_lv.thename= _root.thename.text;
send_lv.company= _root.company.text;
send_lv.email_address= _root.email_address.text;
send_lv.phone = _root.contact_phone_number.text;
send_lv.address= _root.address.text;
send_lv.guests = _root.number_of_guests.text;
send_lv.comments = _root.further_comments.text;
send_lv.room =_root.room_required.getSelectedIndex();
send_lv.layout = _root.Room_Layout_Required.selectedIndex;
send_lv.timing = _root.timing_of_the_event.selectedIndex;
send_lv.thedate = _root.date_required.text;
send_lv.catering = _root.catering_required.selected;
send_lv.brochure = _root.brochure_request.selected;
send_lv.mailing_list = _root.mailing_list.selected;
send_lv.postcode = _root.postcode.text;

send_lv.sendAndLoad("http://www.somdomain.com/php/mail.php", result_lv, "POST");

}


now, if i try and trace any variables or create a new text box on the stage and give it the value of an arbitrary variable declared within sendForm() it ALWAYS comes out undefined!

nothing is being sent as no variables are being declared - even the LoadVars() object is coming back undefined - it's not even instantiating!

As you can see i've even copied the sendandload stuff straight from Flash's help files in order to ensure i'm not missing anything.

Does anyone have any suggestions as to why this could be - i've been on this all morning and it's really getting on my wick now...

How To Declare A Constant In AS
I wonder how to do this, any reserved key?
thanks

How To Declare A Variable
If you type the actions within flash, rather than using an actionscript file, do you need to type:


ActionScript Code:
package { public classs whatever extends whatever

or do you just declare variables within each frame and thats it.

Sorry if it sounds silly.

When Is It Best To Declare A Variable?
In lots of users code I see variables declared on the fly in various functions, eg:


ActionScript Code:
function whatev(num:int){
  var myvar1:int = num
  gotoAndPlay(myvar1)
  var myvar2:int = 7
  trace(myvar1 - myvar2)
}

But isn't it better to declare most variables ONCE at the beginning of your code, particularly if a function gets called more than once? eg:


ActionScript Code:
var myvar1:int
var myvar2:int = 7

function whatev(num:int){
  myvar1 = num
  gotoAndPlay(myvar1)
  myvar2 = 7
  trace(myvar1 - myvar2)
}

This way, the variable is declared only once, instead of declaring a variable over itself everytime a function is called. Isn't this the correct methodology? Doesn't this save some sort of overhead or anything?

What is your input on when/where variables should be declared?

How Do U Declare A Global Variable?
Hi all,
Please help me with this one.
1.How and where do you declare a global variable in action script?
The declaration is going to be followed by the action:
On(release){

}

2.Also, If there are two scripts attached to two different
buttons (in the sane movie),
can variables and functions defined in one be accessed from the other?
I wud be grateful if u can include a sample script illustrating the above.
thanks.
triveni
my e-mail add:trivs17@hotmail.com

How To Declare And Use A 2 Dimensional Array
i need to declare and use a 2 dimensional array ..

i tried a lot of stuff witch don t work!!

please help me !!!!

How To I Declare And Set Custom Variable?
Hi guys I need help making this script work.
I have this on frame 1

Code:
var ButtVar
set (ButtVar, 0);
and this on one of my Button'


Code:
on (release) {
if (ButtVar == 1) {
gotoAndStop(2)
set (ButtVar, 0);
}
else {
gotoAndStop(3)
set (ButtVar, 1);
}
}
what I want to happen is, that when you click on the button the 2nd time it goes back to frame 2.

any help appreciated.
thanks

How To Declare/use A Global Function
I have like 8 movieclips that have this code in all of their 1st frames.


Code:
this.onRollOver = function() {
this.gotoAndPlay(2);
}
stop();
How can i make a global function on the root so that all I have to do is call the function instead of reusing the code over and over again in each movie clip?

Thanks in advance!
Paul

P.S. How would I call it?

How Do You Declare 3 Dimentional Array?
How would you declare a 3 dimentional array in flash 8?

qst = [j,i,t] <<<is that right

How To Declare A New Data Type?
I have a new Data type ( fxn ) declared in delphi, and i would like to convert the code to actionscript

Code:
type fxn=procedure(t:extended;x:array of extended;var f:array of extended);
.....
procedure fp(t:extended;x:array of extended;var f:array of extended);
begin
f[0]:=x[1];
f[1]:=-sin(x[0])*(g/ll);
end;
....

procedure r_kutta6(eps,t0:extended;x0:array of extended;fnx:fxn;
var t:extended;var x:array of extended);
begin
...
fnx(t0,x0,f); //means fp(t0,x0,f); - when applying the procedure.
...
end;

...
r_kutta6(0.0001,t0,xx0,fp,t,xx);
how can i declare in actionscript such a new data type, and after - to use as i do in delphi
thanks!

Can You Declare A Dynamic Variable Name?
I know I can do things like:

i=1;
this["var" + i] = 10;
trace(var1);

//trace = 10



What I need to do is declare that variable. I experimenting with a collision system that uses regions to limit the hit calculations. Basically all collidable particles will be added to their regional array, and since they are small particles, they can only collide with other particles in their array. This will dramatically limit the amount of looping needed per particle per frame.

My problem is right at the beginning where I define the regional arrays though. I want them to be dynamically declared so that I can toy with their sizes later without rewriting the code.

Boiled down, what I want to do is:

i=1;
var this["var" + i] = Array();

This gives me an error. so does
var this["var" + i]:Array = Array();

Is there another way to declare a variable that will let me use a dynamic variable name?

[CS3] [as2] Concatenate And Declare Variables
Hi,
FIRST NOTE this is flash running as an OCX inside a visual basic windows application. Therefor vars from outside can only be passed to the main timeline of the movie, not down to individual mc's. (well so it seems).

I have been trying to find away around having a variety of differing variables in copies of one mc.

on the maintimeline i declare all the varaiables

Code:
var i:Number;
for (i = 0; i < 16; i++) {
//var this["Setpoint" + i]:String
this["Setpoint" + i] = "";
//var this["Actual" + i]:String
this["Actual" & i] = "";
//var this["Ingredient" + i]:String;
this["Ingredient" & i] = "";
}


you may notice I tried to declare them as strings here before assigning values then commented it out.
Flash did not like that syntax, any thoughts on that issue, its not the main problem?

My mc has a "labelText" var which is created in an onClipEvent(load) and is a unique number. The mc inside has a dynamic textbox.
I want to say in the variable field on the properties panel for the dynamic textbox
_root["Ingredients" +_parent.labelText]

This would make each mc look on the root for the var that corresponds with its number for instance mc with the label 3 gets var _root.Ingredient3

can I concatenate a var name like this right in the properies panel?
does not seem to work

thanks
mark

Declare A Variable From Other Variables
Hi to all

I want to declare a variable like this

var3 = var 1 . "some text" . var 2

How can I do this in AS?

thanks

How To Declare A New Data Type?
I have a new Data type ( fxn ) declared in delphi, and i would like to convert the code to actionscript

Code:
type fxn=procedure(t:extended;x:array of extended;var f:array of extended);
.....
procedure fp(t:extended;x:array of extended;var f:array of extended);
begin
f[0]:=x[1];
f[1]:=-sin(x[0])*(g/ll);
end;
....

procedure r_kutta6(eps,t0:extended;x0:array of extended;fnx:fxn;
var t:extended;var x:array of extended);
begin
...
fnx(t0,x0,f); //means fp(t0,x0,f); - when applying the procedure.
...
end;

...
r_kutta6(0.0001,t0,xx0,fp,t,xx);
how can i declare in actionscript such a new data type, and after - to use as i do in delphi
thanks!

Declare A Symbole To Be _global
hi,

i create a movie clip symbol caled "container" in the stage , now i want this symbol in my script to be declared as a _global.container. how can i do it?

Thanks
S

Declare Text As A Number
This has been baffeling me for far too long. How do you define text as a number. I've created this code to simply add two numbers together but if I add 100 + 4 i would get 1004!! Heres the code I have soi far...


ActionScript Code:
var userNumber:Number = 100;
var userNumber2:Number = 40;

testButton.addEventListener(MouseEvent.CLICK,getResultTest);
function getResultTest(Event:MouseEvent):void {
    TestResult.text = ([userNumber]) + ([userNumber2]);
}

Please help!!

Thanx for reading

Using 'eval' To Declare Variables
I'm just curious as to how this works, or doesnt...

I'm familiar with using the eval() function, but what i wanna know why you can't use eval() w/o the use of a property afterwards.

Example1: this would work

ActionScript Code:
for (i=1;i<=3;i++) {
 eval("clip"+i)._x = i*10
}

Example2: this wouldnt work

ActionScript Code:
for (i=1;i<=3;i++) {
 eval("track"+i+"name") = "name of track "+i
}

This really pisses me off whan I'm trying to delcare a lot of variables dynamically; I don't want to have to do it manually in the script.
(I think senocular might be able to answer this one)

Progaramatically Declare Type
Hi There

consider this recursive function:

private function
setChildrenEditable(DObj:DisplayObjectContainer,f:Function):void{
for(var i:int=0;i<DObj.numChildren;i++){
if (DObj.getChildAt(i) is IContent){
//do the function
var c:IContent = DObj.getChildAt(i) as IContent;
f(c);
}else if(DObj.getChildAt(i) is DisplayObjectContainer){
//do the recursion
setChildrenEditable(DisplayObjectContainer(DObj.getChildAt(i)),f);
}
}
}

it takes a display object container and recursively sends all children
of a specific type to function f. What I would like to do is to pass
the type of child that the method looks for so instead of
setChildrenEditable(DObj:DisplayObjectContainer,f:Function):void

it said
setChildrenEditable(DObj:DisplayObjectContainer,f:Function,Type:???):void

I could the make it a nice static method for use in lots of different
situations. Any ideas?


Cheers Richard

How Do I Declare Variables Et C Only ONCE In Function?
Hi. I have a problem with functions and variables.. i need a kind of help with how to get functions that i use every onEnterFrame.
et c:
A MC is using this:
ActionScript Code:
onClipEvent (enterFrame){
_root.randomWalk(target);
}




and this is the functions it calls:
ActionScript Code:
randomWalk = function (target)
{
tXH = target._x + 15;
tXL = target._x - 15;
tYH = target._y + 15;
tYL = target._y - 15;
rwX = Math.round (Math.random () * (tXH - tXL)) + tXL;
rwY = Math.round (Math.random () * (tYH - tYL)) + tYL;
target._x += (target._x - rwX) / 100;
target._y += (target._y - rwY) / 100;
};




As you can see it gets new variables onEnterFrame... How do i get around this?

How Do I Declare A Textfile Gloabaly
I need to declare a text file gloabaly so I can call it within a symbol for a scroll box... How would I go about declareing that............. file name is myText.txt

Declare Variables In A For Loop
Hi guys ... this seems quite a simple thing to do, but i can't do it!!

what i want to be able to do is create variables, one for every value in the for loop, i tried this, but it didn't work:


ActionScript Code:
for (i=5; i>=1; i--) {
    var ["varnumber" + i] = i;
}


thanks in advance

Bongo

How Do You Declare A Variable That Can Be Accessed From Any Scene?
Hi..
Please can you tell me how you can declare a variable that you can access/modify from any scene in a movie..
Thanks

How To Declare A Varable Globle To A Movie
how can i declare a verable globle to the movie and how to get access
it in a particular button


help me out


from
aristotle

[CS3] Declare/Recall Numeric Variables
on Frame one, I want do declare a variable in an input text box. On frame two, I'd like to use that variable in part of my script for the speed of a ball.

Declare Data Types Within An Object?
Hi all. I am creating an object like this:


Code:
var myObject:Object = new Object();
When I add new properties to the object, some will be numbers and others strings.

Is this syntax correct, or do I need to declare the data type for each property?


Code:
myObject.userName = "Joe Smith";
myObject.passed = "yes";
myObject.previousUser = "no";
myObject.programScore = 78;
myObject.screenName = "0301";
Didn't know if I should declare string, boolean and numeric data types within an object or not.

Thank you.

MaryAnne

Declare Window-size In GetURL
Hello!

Is there a way to declare the width and height of the window opened by the code?

on (release) {
getURL("files.swf", "_blank", "GET");
}

Declare Variable Inside For Loop
Hey,

I want to do the following inside a loop.

person1 = data1
person2 = data2
person3 = data3
person4 = data4

etc.

person(+number) is the var name of the dynamic textfield that allready exitst, but the amount of persons is variable..
i want to do something like this

amountofpersons = amountfromphp;
for (var i = 1; i<amountofpersons; i++) {


person+i = "data"+i;

}

I know the "person+i" is wrong, but I dont know how to do it right in actionscript, is it possible to loop variables?

thanx in advance!

Why On(release) Doesn't Declare My Variable?
Hi!
I'm new here and got this problem.

I have these three clips each one containing it's own hit zone inside so I can use them as icons/buttons.

They should redirect my presentation to one of three new scenes but not until having played the final portion (starting on the frame labeled "ENDportion") that clears the screen by taking off some elements.

So, i hope that on(release) makes the animation jump to the final portion of the current scene and declares a variable I named "nextscene" to have one of three values (A, B or C) according to the pressed icon.

//after pressing icon A
on (release)
{
var nextscene = "A";
gotoAndPlay("ENDportion");
}

I use this variable's value at the final frame whose behaviour should make the wanted jump trhough this script:

if (nextscene = "A")
{
gotoAndPlay("SceneA",1);
}
else if (nextscene = "B")
{
gotoAndPlay("SceneB",1);
}
else if (nextscene = "C")
{
gotoAndPlay("SceneC",1);
}
else
{
gotoAndStop("start1");
}

"start1" is the label of a frame where movieclips keep on playing until "restart1" where a behaviour send them back to "start1".

The problem is that, once released, any icon sends me just to the very next scene, the one that comes after the current scene lineally, but not to the other one I intended.

I hope to have been clear enough.
Thanks for any suggestion or correction!

Declare Multiple NetStreams With A Cycle
Hi!

I'm new in AS3 and I have a serious problem...
I need a dozen of NetStreams to create and i thought i colud do it with a for () cycle. But i've tried it a many ways and all of them were wrong.

So the question is: Can i create/declare multiple NetStreams with a for () cycle?
(The goal i want to achieve is to set up a web conference tool where about 12 users see each other on one screen.)

for(var i:uint; i < 13; i++){
var ["ns" + i] : NetStream;
}

thats not correct but i need something like that...is that possible in AS3?
Could anybody pls help me, how to manage these streams?

Thx, malki!

Declare Vars In For Loop For Root
Hey guys, I'm trying to declare 8 vars, but without writing:

ActionScript Code:
var s1:Sound;
var s2:Sound;
var s3:Sound;
var s4:Sound;
var s5:Sound;
var s6:Sound;
var s7:Sound;
var s8:Sound;

or


ActionScript Code:
var s1:Sound,s2:Sound,s3:Sound,s4:Sound,var s5:Sound,s6:Sound,s7:Sound,s8:Sound,

This would be fine for the example, but I'm planning on using the technique for much bigger things.

For the example I want to load 8 songs into these generated vars.

That's fine, but I want to access them elsewhere in the script and/or timeline. So I have a scoping issue. Is there a way to declare a var UP a level?

So what I want to do is something like:


ActionScript Code:
for (var i:Number = 0; i<8; i++){
         var this['s'+i]:Sound = new Sound;
         this['s'+i].loadSound('sounds' + i + '.mp3');
         this['s'+i].stop();
}

Obviously that code does not work because of the var declaration, but I can't figure out how to declare multiple vars in one loop.

So my questions are:

1: How to declare multiple vars in one loop.
2: How to make them accessible to the root, or outside it's scope.

Just Wanna Declare The Variables Before The Enterframe
onClipEvent(load){

}
////////////////////////////////////////////////////////////////////////////////////
is there a similar load event to declare variables before the onEnterFrame is reached because i havve a
var key_press = true;

which is true, but the
var key_press
is recognised as false just skips passed the first part and never adds the value t true to the
var key_press //
/////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////
var key_press = true;/////////here not recognised

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
};



Key.addListener(keyListener);
box.onEnterFrame = function(){
if(Key.isDown(Key.UP)&& key_press == true ) {
box.gotoAndStop("walking_left_back")
box._y -= 5;
trace(key_press)

} else {
key_press = false;/// It adding this value when loaded // not the value of true
trace(key_press)
}
}

Declare Object From Database Or Stringvariable
Dear Scripters!

I have some trouble with the declaration of an object. Since my content-management system has shortage of database fields, I wan't to create some by adding a AS object in a database field (1 database field becomes x fields of the object). Main question: Is it possible to declare an object from a string in a database? Example:

var account:Object = {name:"Macromedia, Inc.",
address:"600 Townsend Street",
city:"San Francisco",
state:"California",
zip:"94103",
balance:"1000"};


All code that is red is stored in the database. The original idea was to read the code from the database and "paste" it in a new object:


ActionScript Code:
function ObjectTest_Result(result) {
    trace("ObjectTests fired");
    var Rs:Object = result;
   
    //trace(Rs.getItemAt(0).note);
   
    var test:String = Rs.getItemAt(0).note;
   
    trace(test);
   
    var account:Object = ["{" + test + "}"];
 
   
    for (i in account) {
      trace("account."+i+" = "+account[i]);
      
    }
    trace("object test = " + account.address);
}

The above code is the result handler from a flash remoting call. The object is declared, but with only one variable instead of 6 (name, adress, city... etc etc). Does anyone know how to declare an object in this matter?

Thnx in advance,

Steven

Declare Variable Data Types
From my understanding, there is no need to declare variables data type like String, Number, Array for it to function. For example:

var abc:String = "abcde";
var abc:Number = 1234;
var abc:Array = new Array();

We can write it in easier way and it is still working.

abc = "abcde";
abc = 1234;
abc = new Array();

So, what is the purpose and benefit to declare the variable specific data type?

How Do I Declare Components' Data As Variables?
ive read the components tut. and actually just tried to use it but its a little to different than what im trying to do. Actually all i need to know is how to declare uicomponents' data as variables that way i can recieve them in my email via php.


example:
www.caltrustmortgage.com/hope.swf

i need to make the radio buttons' and combo box's data sent to my email. I know how to do it with input text but not components.

Passing A Class Type And Declare It
i am trying to pass a class type into a function which then declares it to an array this way:

i have this class which i am using the add movieclips form the library.

PHP Code:



package {
    import flash.display.MovieClip;
    
    public class TestClass extends MovieClip {
        
        private var allTypes:Array;
        
        public function TestClass {
            allTypes = new Array();
        }
        
        public function addType(i:Number, type:*) {
            //then i wanna declare the type of the class that is put into this method
            allTypes[i] = new type("name", 10, 50);
            addChild(allTypes[i]);
        }
    }





and then on my main timeline, i have this document class, which will have an instance of the TestClass, and add in types which i want to add onto the stage. i wish to pass in the type of the class name of the exported movieclips which i have in my libraries.

PHP Code:



package {
    import flash.display.MovieClip;
    import TestClass;
    
    public function MainMovie extends MovieClip {
        
        var TestClass:TestClass;
        
        public function MainMovie() {
            TestClass = new TestClass();
            //now i want to add the Type of the class into the paramaters
            //these types are class names of the movieclips in the library that are exported for actionscript in linkage
            TestClass.addType(0, Plane);
            TestClass.addType(1, Bird);
        }
    }





however, this doesn't seem to work. any idea how should the syntax or the right way be for doing this?
thanks.

String To Object Or Dinamicly Declare A Var
ActionScript Code:
var prslide:slide1 = new slide1;


ok, say i din't want to have it always be slide1. how can i change it at runtime.
for instance make a loop that incremented the value of and did something like

ActionScript Code:
i++var prslide:("slide"+i.toString()) = new ("slide"+i.toString());


this used to be easy in as2

[tough] Any Way To Declare A Custom Event?
Hi,

This might be extremely hard to do or not even possible (as far as I know), but I was wondering if anybody had any code that allowed users to define they own "event" and add a listener for it.

For example (in pseudo code):


ActionScript Code:
event footToGround    code here that detects if players foot mc has tounged the ground mc}function fTG {   trace("foot has touched ground");}stage.addEventListener(footToGround, fTG);
This would eliminate the need for onEnterFrame for constant detection and enhance the performance of a game or website with the less and less onEnterFrames, timers or setIntervals that are used on a Flash application.

How Do I Declare Components' Data As Variables?
ive read the components tut. and actually just tried to use it but its a little to different than what im trying to do. Actually all i need to know is how to declare uicomponents' data as variables that way i can recieve them in my email via php.


example:
www.caltrustmortgage.com/hope.swf

i need to make the radio buttons' and combo box's data sent to my email. I know how to do it with input text but not components.

Declare A Variable Using HTML Tags...
Hi,

You've surly seen how some variables are declared in HTML tags in the <Object....

in your HTML page, where you are entering the path to the flash file, you add something like this:

src="flash.swf?playlist=path/to/file/list.xml"

or some other samples etc...

I'm intrested to find a tutorial or something about the tips of this method but I can't find anything by googling the web. Can anyone here show me some usefull address where I can get some more information about this method?

Thanks,
Hadi

[AS2.0] Declare Nested Clips In Class
I'm having a brain fart this week on just about everything as i haven't written much AS2.0 in months. How do you declare nested clips in AS2.0?

I get errors when I do both of the following:


ActionScript Code:
class VideoPlayer extends MovieClip
{
    // list class vars
    private var Scrubber.Handle_mc:MovieClip
}
 
// and
 
class VideoPlayer extends MovieClip
{
 
    // list class vars
    private var Scrubber:MovieClip
    function VideoPlayer ()
    {
        Scrubber = Scrubber.Handle_mc;
    }
}
 
Is either correct ? I feel so stupid this week.

Declare Object Using String From Database
Dear Shockers!

I have some trouble with the declaration of an object. Since my content-management system has shortage of database fields, I wan't to create some by adding a AS object in a database field (1 database field becomes x fields of the object). Main question: Is it possible to declare an object from a string in a database? Example:


var account:Object = {name:"Macromedia, Inc.",
address:"600 Townsend Street",
city:"San Francisco",
state:"California",
zip:"94103",
balance:"1000"};

All code that is bold is stored in the database. The original idea was to read the code from the database and "paste" it in a new object:


ActionScript Code:
function ObjectTest_Result(result) {
    trace("ObjectTests fired");
    var Rs:Object = result;
   
    //trace(Rs.getItemAt(0).note);
   
    var test:String = Rs.getItemAt(0).note;
   
    trace(test);
   
    var account:Object = ["{" + test + "}"];
 
   
    for (i in account) {
      trace("account."+i+" = "+account[i]);
      
    }
    trace("object test = " + account.address);
}


The above code is the result handler from a flash remoting call. The object is declared, but with only one variable instead of 6 (name, adress, city... etc etc). Does anyone know how to declare an object in this matter?

Thnx in advance,

Steven

Using Eval To Declare A Function On A Movieclip Event
make sence? anyways heres the code:

code: function getMenu(){
delete _root.menuModule;
_root.createEmptyMovieClip("menuModule", 2);

menuModule._x = 0;
menuModule._y = 0;

baseNode = menuXML;
//trace(baseNode);
var menuItems = Array();

for (var x=0; x < baseNode.childNodes.length; x++) {
thisNode = baseNode.childNodes[x];
var children = Array();

for (var z=0; z < thisNode.childNodes.length; z++) {
newNode = thisNode.childNodes[z];
children[z] = Array(newNode.attributes['Text'], newNode.attributes['URL']);
//trace(children[z]);
}

menuItems[x] = Array(thisNode.attributes['Text'], thisNode.attributes['URL'], children);
//trace(menuItems[x]);
}

//populate main menu

for (var y=0; y < menuItems.length; y++){
if(y==0){
x=0;
}else{
z = y -1
x = eval("menuItem" + z + "._x");
x = eval("menuItem" + z + "._width");
//trace(x);
}
_root.createTextField("menuItem" + y, _root.getNextHighestDepth(), x, 0, 105, 18);
this["menuItem" + y].text = menuItems[y][0];
this["menuItem" + y].selectable = false;
this["menuItem" + y].border = true;
this["menuItem" + y].autoSize = "left";

this["menuItem" + y].onRollOver = getSubMenu(y);
}
//trace(menuItems[2]);

}

function getSubMenu(y){
trace("gogo");
}

The problem is in the last loop,

code: this["menuItem" + y].onRollOver = getSubMenu(y);
}
//trace(menuItems[2]);

}

function getSubMenu(y){
trace("gogo");
}
Now what happens is when the script is run, it traces "gogo" twice. (twice because thats how many menuItems there are). They are loaded from a database using php / mysql. Anyways the swf is www.pro-ladder.com/index.swf if you are interested. Im trying to create every element dynamic so joeUser can make his own site. Why does onRollOver run while its going through the loop, but not actually when the mouse "rolls over"?

Declare Object From Database Or String Variable
Dear scripters!

I have some trouble with the declaration of an object. Since my content-management system has shortage of database fields, I wan't to create some by adding a AS object in a database field (1 database field becomes x fields of the object). Main question: Is it possible to declare an object from a string in a database? Example:


var account:Object = {name:"Macromedia, Inc.",
address:"600 Townsend Street",
city:"San Francisco",
state:"California",
zip:"94103",
balance:"1000"};


All code that is red is stored in the database. The original idea was to read the code from the database and "paste" it in a new object:


Code:
function ObjectTest_Result(result) {
trace("ObjectTests fired");
var Rs:Object = result;

//trace(Rs.getItemAt(0).note);

var test:String = Rs.getItemAt(0).note;

trace(test);

var account:Object = ["{" + test + "}"];


for (i in account) {
trace("account."+i+" = "+account[i]);

}
trace("object test = " + account.address);
}
The above code is the result handler from a flash remoting call. The object is declared, but with only one variable instead of 6 (name, adress, city... etc etc). Does anyone know how to declare an object in this matter?

Thnx in advance,

Steven

Declare Class/extending Movie Clip
Hi,

I want to use getDefinitionbyName to call instances of a class onto the stage. I'm just starting to try and get my head around all this, so I'm naybe not 100% understanding everything but here goes...

I'm getting an error message. So think I'm declaring my class incorrectly.

this is the code I want to work:

var mybuttonclass:Class = getDefinitionByName("buttona" + i) as Class;
var symbol:MovieClip = new mybuttonclass();
this.addChild(symbol);

this I would like to bring to the stage a button, well actually a movieclip to the stage everytime a for statement is true. But I get this error message:


ReferenceError: Error #1065: Variable buttona0 is not defined.
at global/flash.utils::getDefinitionByName()
at external_fla::MainTimeline/textReady()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader:nComplete(
)

At the moment I have:


var mybuttonclass:Class = getDefinitionByName("buttona" + i) as Class;
var symbol:MovieClip = new mybuttonclass();
this.addChild(symbol);


buttona0, for example, has "mybuttonclass" set as its class in linkage, and "mybutton" set as its base class. I have the publish settings set to point to a class folder with a class called "mybutton.as". In that I have written:



Code:
package
{
import flash.display.*;
public class mybutton extends MovieClip
{

function mybutton()
{
trace("This works");
}
}
}


Any help/advice or links would be very gratefully received!

Declare Class/extending Movie Clip
Hi,

I'm a "newbie", so please tell me if I'm posting in the wrong place... but I am using AS3.

I want to use getDefinitionbyName to call instances of a class onto the stage. I'm just starting to try and get my head around all this, so I'm maybe not 100% understanding everything but here goes...

I'm getting an error message. So think I'm declaring my class incorrectly.

this is the code I want to work:

var mybuttonclass:Class = getDefinitionByName("buttona" + i) as Class;
var symbol:MovieClip = new mybuttonclass();
this.addChild(symbol);

this I would like to bring to the stage a button, well actually a movieclip to the stage everytime a for statement is true. But I get this error message:


ReferenceError: Error #1065: Variable buttona0 is not defined.
at global/flash.utils::getDefinitionByName()
at external_fla::MainTimeline/textReady()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunctio n()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader:nComplete(
)

At the moment I have:


var mybuttonclass:Class = getDefinitionByName("buttona" + i) as Class;
var symbol:MovieClip = new mybuttonclass();
this.addChild(symbol);


buttona0, for example, has "mybuttonclass" set as its class in linkage, and "mybutton" set as its base class. I have the publish settings set to point to a class folder with a class called "mybutton.as". In that I have written:



Code:
package
{
import flash.display.*;
public class mybutton extends MovieClip
{

function mybutton()
{
trace("This works");
}
}
}


Any help/advice or links would be very gratefully received!



p.s. my total script so far, for essentially a slideshow that pulls buttons 1-n from the library according to how many images there might be, is:



var external_txt:TextField = new TextField();
var externalReq:URLRequest = new URLRequest("external.txt");
var externalLoad:URLLoader = new URLLoader();

externalLoad.load(externalReq);

externalLoad.addEventListener(Event.COMPLETE, textReady);



function textReady(event:Event):void
{
external_txt.text = event.target.data;

var _buttonText = external_txt.text;
trace (_buttonText)
var _n:Number = parseInt(_buttonText);

//var symbolClass:Class = getDefinitionByName("CustomSymbol") as Class;

// Now you can create a new instance of that class we got from above
//var symbol:CustomSymbol = new symbolClass();

for(var i=0;i<_n;i++){

var mybuttonclass:Class = getDefinitionByName("buttona" + i) as Class;
var symbol:MovieClip = new mybuttonclass();
this.addChild(symbol);


trace(_n)

}
}

Is It Possible To Declare Array Inside Movie Clip?
If it's possible, how?
And how to access it's value?

I've been trying like this:

mymovieclip.myArray = ["mc0","mc1","mc2","mc3"]

and I try to access it's value via:
mymovieclip.mc0 = function(){
do this
else
do that
}

and doesn't work.

Thanks

Is It Possible To Declare Array Inside Movie Clip?
If it's possible, how?
And how to access it's value?

I've been trying like this:

mymovieclip.myArray = ["mc0","mc1","mc2","mc3"]

and I try to access it's value via:
mymovieclip.mc0 = function(){
do this
else
do that
}

and doesn't work.

Thanks

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