Functions And Variables?
i have a set of named functions in numerical order, named load1(), load2(), load3(), load 4(), and so on that carry out some actions based on the release event of their corresponding numbered buttons (ie pressing "button 1" executes the load1() function).
i also have a "previous" button and a "next" button that i would like to use as a means of calling either the preceeding or subsequent function, (relative to the user's 'current' numeric position in the button sequence.) so in other words, if the user was viewing page 8, which was loaded by the named function load8(), and the "next" button was pressed, i'd like for the load9() function to be called dynamically and executed.
what i'm stuck on is figuring out how to feed my named functions loadPrev() and loadNext() a number that's essentially going to change everytime a new page is loaded. i created a variable "currentload" to keep track of what function number is currently loaded. What i'd like to know is if there's any way i can introduce that variable into the prev/next functions so that i can consistently execute the matching function number that corresponds to the value of "currentload"
here is what the function definitions look like, essentially:
function load 1,2,3,4, whatever() {
loadMovie("art_1.jpg", "_parent.imagebox");
loadMovie("BTNS-art1.swf", "_parent.buttonbox");
loadVariables("TXT-art1a.txt", "_parent.infobox");
currentload = 1
}
function loadPrev(){
currentload = currentload - 1
newload = currentload
fnc["load" + newload]()
}
function loadNext(){
currentload = currentload + 1
newload = currentload
fnc["load" + newload]()
}
where the parts in red are obviously problematic. basically that's where i would execute whatever function number resulted from the new value of "currentload".
here is the bit of handling code:
btn1.onRelease = load1
btn2.onRelease = load2
btn3.onRelease = load3
btn4.onRelease = load4
(etc...)
btnPrev.onRelease = loadPrev
btnNext.onRelease = loadNext
it seems that this should be a fairly straightforward thing. i'm still a bit of a newbie with actionscript and so i'm not quite sure if how i'm going about this is even sound. any help would be greatly appreciated.
-victor
ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)
Posted on: 11-17-2005, 06:37 PM
View Complete Forum Thread with Replies
Sponsored Links:
- Class Functions Not Able To See Other Member Functions/variables?
- Variables And Functions
- Ug Variables In Functions... HELP
- PHP Variables And Functions
- Using Variables In Functions...
- Variables In Functions
- Using Variables Outside Of Functions
- Variables Outside Functions
- Variables And Functions
- Functions - Variables
- Functions - Variables
- Variables, Functions, Properties
- Problem With Variables Within Functions.
- Using Imported Variables In Functions
- Passing Variables To A Functions
- Variables And Functions In Different Levels...how To?
- Variables, Functions And Levels
- SIMPLE Functions/variables Please Help
- Global Variables And Functions?
- Variables In Math Functions.
- Does AS 2 Not Allow You To Get Variables From Functions Anymore?
- Dynamic Variables In Functions
- [F8] Dynamic Variables In Functions
- Paths Variables And Functions
- [F8] Functions, Intervals And Variables
- Using Variables From Event Functions
- PHP Variables And Logical Functions
- Passing Variables Thru Functions?
- Reuse Variables In Functions
- Global Variables And Functions
- Static Functions + Variables
- Referencing Variables In Other Functions?
- Functions And Incrementing Variables?
- Help With XML Variables -- Arrays, Functions, Etc
- Passing Variables To Functions
- Accessing Outside Variables From Functions
- Help With XML Variables -- Arrays, Functions, Etc
- Class Variables In On Functions?
- Paths Functions And Variables
- Help Passing Variables Between Functions
- Accessing Outside Variables From Functions
- Help With XML Variables -- Arrays, Functions, Etc
- Calling Variables And Functions From One MC To Another MC
- Variables & Components & Functions Help
- Functions And Variables... Important Doubt
- Not Clear On Global Variables And Functions...please Help
- Functions - Problem With Feeding In Variables
- Variables, Functions, Timelines & Scope
- Passing Variables To Functions Like Javascript?
- Functions And Variables Not Recognized Throughout Program
- Problems With Functions And Variables HEEELLLPP
Class Functions Not Able To See Other Member Functions/variables?
I am having a problem which has crept up on me a few times now. I am trying to call another member function within the same class, but Flash is unable to recognize it. This also happens when I try to read values of come variables.
For example, here I am trying to set the private boolean member variable to the state of the checkbox.
//NOTE: This is an EventListener. Does this change something major?
private function CheckBoxClick( evt )
{
_enabled = _root["test_sp"].content[_checkBoxName].selected;
trace( _checkBoxName + " checked: " + _root["test_sp"].content[_checkBoxName]._y );
}
This will output the following: "undefined checked: undefined"
Now in the function directly above it, I have the following function:
public function SetYPosition(pos:Number)
{
trace( _checkBoxName );
_root["test_sp"].content[_checkBoxName]._y = pos;
}
And this function will correctly output the checkbox name as well as update the position.
If I try adding the function call "SetYPosition(500);" to the first function (CheckBoxClick), the function will never be called as if Flash cannot see it.
In the past I have avoided this by using the global instance of the class such as _global.settings.function(blah), but the class I am working on now does not have a global instance.
Any ideas? This is really annoying!
Thanks!!!
Edited: 06/27/2007 at 03:30:12 PM by JoMasta
View Replies !
View Related
Variables And Functions
My movie has dynamically loaded variables on the main timeline like this:
tmp1=wo
tmp2=lz
tmp3=lz
etc.
The first sides of my variables must tell where(position), and the right sides what mc.
I hoped it would work like:
//firstly, for tmp1
if (tmp1 = wo) {
this.attachMovie("womc", "womcnew", 0);
womcnew._x = 137;
womcnew._y = 23;
}
if (tmp1 = lz) {
this.attachMovie("lzmc", "lzmcnew", 0);
lzmcnew._x = 137;
lzmcnew._y = 23;
}
//etc.
//and then for tmp2 and so on
if (tmp2 = wo) {
this.attachMovie("womc", "womcnew", 0);
womcnew._x = 42;
womcnew._y = 160;
}
if (tmp2 = lz) {
this.attachMovie("lzmc", "lzmcnew", 0);
lzmcnew._x = 42;
lzmcnew._y = 160;
}
How would it be reasonable to do this? How can I use variables to tell movie what to do?
View Replies !
View Related
Ug Variables In Functions... HELP
Here's an example of the problem I'm having:
Code:
function foo(alpha, beta, gamma)
{
...
x = alpha;
y = beta;
z = gamma;
...
trace(x);
trace(y);
trace(z);
...
}
the only thing the trace will show is the x. I cannot, in any way, figure out how to find the values of beta and gamma. It's like they don't exist.
This is in Flash 5.
Any ideas?
FrankenMoro
View Replies !
View Related
PHP Variables And Functions
I know you guys get this one alot but my script is alittle different than the examples.
Have this php file:
<?php
$page = str_replace("php","html",$SCRIPT_URL);
include("folder/$page");
?>
This script should load the name of the file (flash.php) and then go get the content in another folder (folder/flash.html).
How do I run this script in flash?
~JRS
View Replies !
View Related
Using Variables In Functions...
function createAboutSubMenu(_old,_new,_Slevel,_endX,_txtNam e,_txtVal) {
duplicateMovieClip(_old,_new,_Slevel);
this[_new]._x = -300;
this[_new]._y = 140.6;
tweenBallX(this[_new]._x,this[_new],_endX);
this[_new].createTextField(_txtName,51,0,0,121,18);
this[_new]._txtName.text = _txtVal;
this[_new]._txtName.setTextFormat(my_fmt);
}
//the createTextField part doesn't work, _txtName is a variable, what could be hte problem here?
View Replies !
View Related
Variables In Functions
how do you get a var to work inside a function? if not is there a simple alternative?
this is what i have & the mc instance (graf) is not moving to the correct location, it worked before i grouped it as a function, any help?
Code:
var TopTween:Number = Stage.height /2-300;
var LeftTween:Number = Stage.width /2-350;
function grafselect() {
graf.tween("_x", LeftTween, 5, MyType);
graf.tween("_y", TopTween, 3, MyType);
}
View Replies !
View Related
Variables Outside Functions
I have a question, regarding how to make a variable inside afunction be recognized by another function... for example say I want to make the variable t increment itself by one every second, and then be recognized outside that function...
SetInterval(function (){t+=1; return (t):},1000);
someother function (){trace(t);}
of course that doesn´t work, it says undefined
or even just a trace(t); that is not inisde a function, will only trace the inital value of t... help, please!
Another question, is there anyother way of making a variable increment, without using the onEnterFrame or the SEtInterval?
View Replies !
View Related
Variables And Functions
hi
ive looked through lots of flash tutorial websites and LOTS of them use variables and functions but i dont understand what they do, how to use them, or why to use them.
if someone could run me through this that would be great
View Replies !
View Related
Variables, Functions, Properties
hey all...
i need a quick hand with functions, variables and properties.
essentially i have a button (A) that calls a movie clip (B) which in turn changes the properties of another movie clip (C) on the stage. right now, this is happening manually... ie, (B) has it hardcoded on a frame.
eg:
with (_root.c) {
setProperty ("_root.c", _xscale, _xscale-2);
setProperty ("_root.c", _yscale, _yscale-2);
}
what i'd like for is that button (A) pass a variable to (B) with the name of the object it would like manipulated. i can't seem to get this working. what would the action script look like for button (A) and what would the script look like for the frame in movie clip (B)?
any help on this will be godsent!
best!
View Replies !
View Related
Problem With Variables Within Functions.
Can Anyone explain why the variable "counter2"
doesn't seem to load properly the first time??
The movie must leave this frame, then re-enter it before the counter2 in the following code works correctly.
Thanks!
Code:
// START OF XML
event = new XML();
event.onLoad = xmlprocess;
event.load("events.xml");
function populateCalendar (i) {
if (event.childNodes[i].nodeName == "EVENT") {
desOut = event.childNodes[i].attributes.des;
dateOut = event.childNodes[i].attributes.date;
dateholder = new Array();
dateholder = dateOut.split("/");
eval("event"+counter) = new Array(dateholder[0], dateholder[1], dateholder[2], desOut);
counter++;
}
}
function xmlprocess (sucess) {
play();
counter2 = event.childNodes.length;
if (sucess) {
for (var i = 0; i<=event.childNodes.length; i++) {
populateCalendar(i);
}
}
}
// END OF XML
// START OF EVENT PARSING
function parsevent (init, counter2) {
for (start=0; start<=counter2; start++) {
if (year == eval("event"+(start+1))[2]) {
// Check if event is in current year
if (curmonth+1 == eval("event"+(start+1))[1]) {
// Check if event is in current month
day = eval("event"+(start+1))[0];
numday = int(day);
build = new Date(year, curmonth, 1);
init = build.getDay();
var boxpos = (numday+(init-1));
eval("e"+boxpos).gotoAndStop(2);
}
}
}
}
// END OF EVENT PARSING
// START OF CALENDAR
delete disp;
disp = new Date();
curmonther = disp.getMonth();
curyear = disp.getYear();
yearer = curyear+1900;
if (!run) {
curmonth = curmonther;
year = yearer;
monthoffset = 0;
run = true;
} else {
// Following Loop allows transfer between years
if (curmonth<0) {
year--;
curmonth = 11;
} else if (curmonth>=12) {
year++;
curmonth = 0;
monthoffset = 0;
}
}
montharray = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
monther = montharray[curmonth];
build = new Date(year, curmonth, 1);
init = build.getDay();
numdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
leap = year%4;
if (leap == 0 && curmonth == 1) {
numdays[1] = 29;
}
end = numdays[curmonth];
boxes = new Array();
for (start=1; start<=end; start++) {
assign = (start+(init-1));
boxes[assign] = start;
}
for (start=0; start<=37; start++) {
eval("b"+start) = boxes[start];
}
play ();
View Replies !
View Related
Using Imported Variables In Functions
I want to use a value in a variable that I have loaded from a txt file into the _root of my movie.
It is called "diff"
If i manually enter a value i.e. "4" the code works fine.
But using the variable diff it does nothing.
I have tested that the variable value is there by writing it to the page in a text box.
Why won't the value be used in the function ????
// diff = my loaded var
amount = diff;
while (amount>0) {
duplicateMovieClip (_root.div, "div"+i, i);
setProperty ("div"+i, _x, random(600));
i = i+1;
amount = amount-1;
}
If i use this
amount = 4;
while (amount>0) {
duplicateMovieClip (_root.div, "div"+i, i);
setProperty ("div"+i, _x, random(600));
i = i+1;
amount = amount-1;
}
it works.
View Replies !
View Related
Passing Variables To A Functions
Hi,
this is my first post but I've gained so much help from reading other peoples post for months now and I figure if im stuck why not call for help.
Im working on a flash platformer game and im trying to use some functions to help streamline some of the processes but im having problem with using functions in flash. I wrote a function called testAhead(direct, xDist, yDist) that returns nothing but tests the distance of the movieClip that calls it to the backroung movieClip graphics. The function is supposed to give new values to xDist and yDist depending on a while loop. I know the inner part of the function works cause when i use the inner loop inside a movie clip it works. How do I get the function to assign values to the variables that i pass to it? I remember in C, (i think, i took C a long time ago) that you put '&' in front of the variables that you want to redefine within the function. I forgot what this is called. Can some one tell me if this is even possible in ActionScript?
The Shnoz
-----
http://www.audiokio.com
View Replies !
View Related
Variables And Functions In Different Levels...how To?
Hello,
i created a movie with a preloader in level 0. The main movie is loaded into level 1 and the other movies are loaded in level 2.
I have several variables and functions in level 0:
_root.window; _root.close; function fadeIn; function fadeOut, etc.
My problem is when i do something like:
MC.fadeIn(10) or if(_root.window==1) { ...
it doesn't work...i think maybe it's because i write this in level 1 MC and the funtions and variables are in level 0.
Could someone help me with this?
by the way: i load the .swf files in a content MC named "content" but if the variables and functions are in _root, so this shouldn't aftect anything cause i should still refer to _root.window, as an example.
Thanks,
Miguel
View Replies !
View Related
Variables, Functions And Levels
Hello,
in my flash web site i have level 0 and level 1. Some MC from level 1 should you variables from level 0 and functions created in level 0 but until now i wasn't able to make it work because i have been using it as everything in same level...i think that's my mistake.
i use for example, when working in level 1:
_root.window=1; but this variable is in level 0
MC.fadeIN(10, 80); but this functions is in level 1
so how to i this?
and by the way, if i am working on a variable in level 1 and i say _root.var, i am assuming the root from level 1? I mean, each level has a root? Could someone explain to me this or give me some link for me to look at it?
Thanks,
Miguel
View Replies !
View Related
SIMPLE Functions/variables Please Help
i am SO STUCK!!
i am trying for the first time to write my own function and change variables.
i am using levels.
i want it so that i click a button, and bugs run onto the screen
i click another button - the first bugs run off, and new bugs run onto the screen.
SIMPLE!
but hard for me.
i think i know how to set the value of the variable ok, but how to translate that into the name of the movieclip i want to command??
level0main.swf is the main clip
so here's my function:
PHP Code:
loadMovieNum("level50btns.swf", 50);
loadMovieNum("level20bugs.swf", 20);
newbug = 0;
currentbug = 0;
lastbug = 0;
function changebug() {
if (lastbug = 0) {
currentbug = newbug;
_level20.currentbug.gotoAndPlay("in");
}else{
_level20.lastbug.gotoAndPlay("out");
lastbug = currentbug;
currentbug = newbug;
_level20.currentbug.gotoAndPlay("in");
}
}
and my buttons say:
PHP Code:
on (release) {
_level0.newbug = b4;
_level0.changebug();
}
please help! i really want to crack this!!
i know atleast one thing wrong, i need the value of the variable in the path "_level20.currentbug.gotoAndPlay("in");"
not the variable itslef - cos it looks like it's a movieClip.....
View Replies !
View Related
Global Variables And Functions?
Hi guys, below I'm declaring a global variable for getting the totalBytes of an XML file but how come even tho its declared as a global variable I can't trace output the value of "XMLSize" with my "trace(_global.XMLSize)" at the end of this script? Could someone shed light on global functions too? Thank you all!
:P
:P
userInfo = new XML();
_global.XMLSize;
userInfo.ignoreWhite = true;
userInfo.load('userInfo.xml');
userInfo.onLoad = function() {
_global.XMLSize = userInfo.getBytesLoaded('userInfo.xml');
XMLOut(this);
}
function XMLOut(xml_file){
for ( a = 0; a < xml_file.firstChild.childNodes.length; a++) {
for(z = 0; z < xml_file.firstChild.firstChild.childNodes.length; z++){
trace(xml_file.firstChild.childNodes[a].childNodes[z].firstChild.nodeValue);
}
}
}
trace(_global.XMLSize);
View Replies !
View Related
Variables In Math Functions.
Hi all,
I was wondering if anyone can help.
In my flash movie the follwing code works fine:
_root.num = random(10);
_root.holder.box.text = eval ("_root.content_"+num);
Basically this code creates a random number which is then added to "_root.content_" to randomly select some text for a dynamic text field.
However, rather than defining the upper limit of the random selection with a number (ie 10), I want to pass in a variable from a text file (_root.value). The code that I am using is:-
_root.num = Math.floor(Math.random()*_root.value);
_root.holder.box.text = eval ("_root.content_"+num);
But this does not work. NaN is being returned.
Any help would be really appreciated!!!
Thanks,
Maw.
View Replies !
View Related
Does AS 2 Not Allow You To Get Variables From Functions Anymore?
Hi all
I have an xml file being retreived and the details sorted out into arrays to then be read by mc's.
As follows:
Code:
var gridXML:XML = new XML();
gridXML.ignoreWhite = true;
gridXML.onLoad = function(success) {
if (success == true) {
trace("gridXML success");
stripXML();
} else {
trace("gridXML fail");
}
};
function stripXML() {
var grid_RootNode:Array = gridXML.firstChild.firstChild.childNodes;
var noOfItems:Number = grid_RootNode.length;
var itemNameArray:Array = new Array();
var itemClientArray:Array = new Array();
var itemTypeArray:Array = new Array();
var itemImageURL:Array = new Array();
for (i=0; i<noOfItems; i++) {
itemNameArray[i] = grid_RootNode[i].attributes.itemName;
itemClientArray[i] = grid_RootNode[i].attributes.itemClient;
itemTypeArray[i] = grid_RootNode[i].attributes.itemType;
itemImageURL[i] = grid_RootNode[i].attributes.itemImageURL;
}
trace("TRACE 1 = "+itemNameArray);
play();
}
gridXML.load("xml/grid.xml");
stop();
The "TRACE 1" comes out no problems with the values of itemNameArray but if I trace out on the next frame the value of itemNameArray it is undefined.
Basically I cant obtain the values outwith the function 'stripXML'
I am new to AS 2, am I missing a path here or anything??
View Replies !
View Related
Dynamic Variables In Functions
(am using Flash 8)
On my stage I have 3 movies, M1, M2 and M3 and a dynamic text box set to show the variable 'txt'.
On my 1st frame I have the actionscript:
Code:
for (j=1; j<=3; j++){
_root["m"+j].onPress=function(){
_root.txt=j;
}
}
What I want to be able to do is to display either the number 1, 2 or 3 DYNAMICALLY in the text box depending on whether M1, M2, or M3 was selected.
The code above will always show '4' in the text box nomatter which movie is selected. (due to the function obviously being called after for loop has finished)
How do I resolve/rewrite this please (it is imperitive that M1-M3 are kept as movie symbols)?
(please note that what I have done here is very a very simlified version of what I am tring to do, however if someone can solve this problem for me, then I can apply the result to my more complex project. Thanks)
Cheers! (P.S an example .fla FLash 8 file is enclosed).
View Replies !
View Related
[F8] Dynamic Variables In Functions
On my stage I have 3 movies, M1, M2 and M3 and a dynamic text box set to show the variable 'txt'.
On my 1st frame I have the actionscript:
Code:
for (j=1; j<=3; j++){
_root["m"+j].onPress=function(){
_root.txt=j;
}
}
What I want to be able to do is to display either the number 1, 2 or 3 DYNAMICALLY in the text box depending on whether M1, M2, or M3 was selected.
The code above will always show '4' in the text box nomatter which movie is selected. (due to the function obviously being called after for loop has finished)
How do I resolve/rewrite this please (it is imperitive that M1-M3 are kept as movie symbols)?
(please note that what I have done here is very a very simlified version of what I am tring to do, however if someone can solve this problem for me, then I can apply the result to my more complex project. Thanks)
Cheers! (P.S an example .fla FLash 8 file is enclosed).
View Replies !
View Related
Paths Variables And Functions
Hi!
I am having problems with a production I am making. Here's the description:
I have a variable in the _root called 'ordered'. I have another variable called 'total' inside a function called 'loadXML'. 'total' receives a number value from a node in a XML file correctly. I now want to transfer this value to the variable 'ordered' which, as I said, is in the _root.
However, 'total' is restricted to the function and I can't access it from the variable in the _root. Neither can I transfer the value from the variable in function to the _root.ordered, since such a line targets the _root of the function itself.
I guess this isn't too hard to solve, probably just a path issue, but I have a few rather large gaps in my knowledge of actionscripting. Can anyone help?
On the stage, there are three objects; a movieclip with the instance name 'clip', a movieclip with the instance name 'orderbox' and finally a dynamic text field with the instance name 'pos_txt'.
My code is on frame 1 and reads as follows:
Code:
System.useCodepage = true; // makes scandinavian charachters work.
// SET COUNTER
var kits = 500;
ordered = 486; // Just an initial value which is replaced later
var kitsleft = kits - ordered;
var counter = kitsleft;
//FUNCTION FOR COUNTER
loadXML = function (loaded)
{
if (loaded)
{
xmlNode = this.firstChild;
total = xmlNode.childNodes[0].firstChild.nodeValue;
//countertext = xmlNode.childNodes[0].childNodes[0].firstChild.nodeValue;
counterfunc(); // triggers function which loads value into dynamic textfield.
}
else
{
content = "file not loaded!";
} // end else if
} // End of the function
counterfunc = function() //Function that shoots the value into dynamic text field
{
pos_txt.text = 500 - total + " Tandvårdskit kvar"; // The text that is shot
_root.ordered = 500 - total; // tries to load value from xml variable "total" into "ordered"
} // End of the function
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("counter2.xml");
p = 0;
//CREATE MOVIE CLIPS
var col = 10; // # of columns
var row = 50; // # or rows
var allboxes = col*row; // # of MC's/cells in grid
var startX = 472 ; // horizontal starting position grid
var startY = 2498; // vertical starting position grid
var offsetX = -50; // horizontal offset
var offsetY = -50; // vertical offset
// RANDOM FUNCTION
Array.prototype.shuffle = function () {
this.sort(function () {return random(2) ;}) ;
} ;
// ARRAYS FOR STORING ORDERED AND REMAININGKITS
var orderedclipsArray:Array = new Array();
var remainingclipsArray:Array = new Array();
// MAKE THE GRID
for (i=0; i<allboxes; i++) {
duplicateMovieClip(_root.clip, "clip"+i, i);
theMC = _root["clip"+i];
theMC._x = startX+(i%col)*offsetX;
theMC._y = startY+Math.floor(i/col)*offsetY;
remainingclipsArray.push("clip"+i); //stores all movieclips in an array
}
//REMOVE ORDERED KITS FROM ARRAY
for (i=0; i<ordered; i++) { //actions below is based on the amount of ordered kits
remainingclipsArray.pop("clip"+i); //removes all ordered movieclips from the array and leaves the ones left
orderedclipsArray.push("clip"+i); //stores all ordered movieclips in an array
}
orderedclipsArray.shuffle(); // Shuffles the listed items in the array of ordered kits
//trace (orderedclipsArray);
//REMOVE ORDERED KITS FROM STAGE
for(i=0 ; i<ordered; i++){//actions below is based on the amount of ordered kits
removeMovieClip(eval(orderedclipsArray[i])) // removes the ordered kits from the stage
}
I also have an XML-file called counter2.xml with the following code:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<orderlist>
<orders>486</orders>
</orderlist>
View Replies !
View Related
[F8] Functions, Intervals And Variables
So, I want to make a function that makes a MovieClip rotate. Sounds simple enough, right? Well, onEnterFrame can't be used, because only one onEnterFrame can be used, and the clip already has one. So, I have this.
Code:
//in SomeClass
public static function startRotate(mc, spd, acl)
{
mc._rotation += spd;
spd += acl;
}
//in main timeline
setInterval(SomeClass.startRotate, 2000, 2,3)
The problem lies in that, by calling the function each time, spd and acl are both reset. So, my question is, how do I go about fixing this? Have I gone about it in a completely wrong way? Whats the best way to do this?
Thanks for the help,
Halcyon
View Replies !
View Related
Using Variables From Event 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:
Code:
//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 result is not what i espected...
Code:
A tocar
Null
Why NULL ???????
What is wrong or missing???
Anyone?
View Replies !
View Related
PHP Variables And Logical Functions
Hi there,
well i guess i got a stupid question but i cant figure it out
Code:
var zoeken:URLRequest = new URLRequest("http://www.zvcvegatigers.com/PHP/aanwezig.php");
var lader:URLLoader = new URLLoader();
lader.dataFormat = URLLoaderDataFormat.VARIABLES;
lader.load(zoeken);
lader.addEventListener(Event.COMPLETE, laden);
function laden (event:Event):void
{var karel_beslist:String = lader.data.dag2_10;
trace(lader.data.dag2_10);
trace(karel_beslist);
if (karel_beslist == "neen") {karel_mc_a.gotoAndStop(2);}
is use the as3 above to obtain values from a php page
by tracing i can confirm i receive the values properly.
BUT
when i use those values in a logical function they don't work
anyone sees a mistake in the code above ?
Cause i got an terrible headache from watching it for some time
Thanks in advance for thos trying to help,
Greetz to all
View Replies !
View Related
Passing Variables Thru Functions?
Hi.
My problem is this: I have the function block, which holds several other functions. I need to pass jpgX through to the sub function floaterBox_mc.viewDetails_mc.onRelease. However, every time I execute it, the trace(jpgX); always gives me the same thing. There must be a way to pass the variables thru, correct?
Any ideas? Thanks!
PS- please excuse my terminology if it is incorrect
Code:
block = function (btn, bTitle, detail_jpg, pdf, jpgX, jpgY) {
this.btn = btn;
this.bTitle = bTitle;
this.pdf = pdf;
this.jpgX = jpgX;
this.jpgY = jpgY;
btn._alpha = 0;
btn.onRollOver = function() {
newX = this._x;
newY = this._y;
oldBtn = newBtn;
newBtn = this;
if (oldBtn != newBtn) {
fadeOutItem = fadeOut(oldBtn);
newW = 302;
}
floaterBox_mc.titleBox_txt.text = bTitle;
};
floaterBox_mc.fBoxArrow_mc.onRelease = function() {
growItem = growWH(floaterBox_mc.fBoxBg_mc);
};
floaterBox_mc.viewDetails_mc.onRelease = function() {
//this always traces "-1307",
//the property from the last BLOCK object in the list:
trace(jpgX);
};
};
block600b = new block(fBlock600b_mc, "Block 600B", "plans/planGround.jpg", "pdf/block110.pdf", -623, -8);
block700 = new block(fBlock700_mc, "Block 700", "plans/planGround.jpg", "pdf/block110.pdf", -623, -8);
block800 = new block(fBlock800_mc, "Block 800", "plans/planSecond.jpg", "pdf/block110.pdf", -1307, -47);
View Replies !
View Related
Reuse Variables In Functions
Hi I'm have some issues trying to access one of my global variables within another function as a part of a class. Here is what I mean.
Code:
class ABC {
var Z:Number;
var num1:Number;
var num2:Number;
var SomeNumber:Number;
function ABC(Z:Number) {
getNum(Z);
}
public function getNum (z:Number) :Void{
Z= num1+num2;
}
public function Equalto(){
Z==SomeNumber;
trace("The two numbers are Equivalent");
}
All I want to do is be able to reuse Z. Right now if I try to use it in Equalto function it returns undefined
View Replies !
View Related
Global Variables And Functions
Hi,
If anyone out there can help me out that would be great.
I am trying to figure out how to control 2 global variables with the same function. The code below outlines 1 global variable and a function which sequentially changes the alpha level of any of the 4 items clicked on.
My question is, say i want to introduce another global variable with 4 different items:
_global.items02 = [e, f, g, h];
how do i make the function control items in items02 using the same sequence?
In other words, if item 'a' is clicked, i would like item 'e' to be affected as well. Clicking on item 'b' should affect item 'f' ... you get the idea.
Thanks!
////////////////////////////////////////////////
stop();
_global.items01 = [a, b, c, d];
function items () {
for (i=0; i<items01 .length; i++) {
if (i != chosen) {
items01 [i]._alpha = 20;
}
}
}
for (i=0; i<items01 .length; i++) {
items01 [i].i = i;
items01 [i].onRollOver = function() {
this._alpha = 40;
items ();
};
}
View Replies !
View Related
Static Functions + Variables
Hi guys.
When I'm trying this code, I always get the next error:
ActionScript Code:
public static function closeHandler(evt:Event):void {
So.data.arrNewCity = arrNieuwStad;
So.data.arrNewLocation = arrNieuwLocatie;
this.stage.nativeWindow.close();
}
"1042: The this keyword can not be used in static methods. It can only be used in instance methods, function closures, and global code."
Anyone who knows how to solve this problem?
Thnx a lot
View Replies !
View Related
Referencing Variables In Other Functions?
OK, so I know this is a total noob question and frankly, I'm ashamed to be asking it, but here goes. What is the syntax for referencing variables defined in other functions? Say I have a something like this for one function: (simplified down of course)
ActionScript Code:
function function1() {
var tween1 = new Tween(etc, etc....);
}
Can I reference variables in function1() and use them in another function like so?
ActionScript Code:
function function2() {
function1()
//Can I call tween1.onMotionFinished = function() from here?
}
I'm sorry if this doesn't make sense, but this is the best way I can explain it. Bascially, how can I reference var tween1 in function1() from function2()?
View Replies !
View Related
Help With XML Variables -- Arrays, Functions, Etc
I have been working on a Flash movie that loads variable data from an external XML file and dynamically displays the item names in a menu which may then be clicked to display other dynamically-loaded content that corresponds to the menu item that was clicked.
I have now come to a standstill in the project as there is something I'd like to achieve but simply cannot work out how. This is my first attempt at working with XML in Flash and one of my early attempts at using variables.
What I'm trying to achieve is; once the user has viewed the item's content, they can simply click "next" and "previous" buttons to display all of the content for the next or previous items in the XML document.
I know it probably sounds simple and I'm sure some of you could achieve this in 5 minutes (!) but I can't get my head around some of the coding. I assume previousSibling and nextSibling would come into play here as well as some sort of functions which access arrays of data for the previous and next items, but I'm just not sure how to correctly put these things to use.
Rather than post my code and example images of the stage up here on the forums, I've created an html page here: http://www.basemedia.com.au/hosted/help
Please, if you think you can be of any help, check it out. I would really appreciate it.
Thanks.
View Replies !
View Related
Passing Variables To Functions
Hi,
I'm relatively new to actionscript and have been chugging away at it for the last couple of weeks. I'm trying to call a function on a button press. This is easy enough, but when I then change this function so that it accepts arguments it all goes it a bit wrong. Even just adding a string as an argument and tracing this to the screen causes problems...
Basically I want the function to be called with an arg when a button is pressed so something like:
mybutton.onRelease = myfunction(1);
myfunction(i:Number) Void
{
trace(i)
if (i == 1)
{
do something;
}
else
{
do something else;
}
}
What ends up happening is that when I test the movie the function is called straight away, and then fails to work when the button is pressed. If I get rid of the arguments then it works fine, only printing the number to the screen when the button is pressed. If I change the button press so that is calls the function without sending the argument, then 'undefined' gets written to the screen (but at least it picks up that the button has been pressed unlike when I pass an argument).
All the tutorials I've looked at seem to have this as the standard way of passing arguments to a function so I'm a little bit in the dark as to what is going on. Any help would be greatly apprieciated.
Cheers,
Tom
View Replies !
View Related
Accessing Outside Variables From Functions
I can't figure out how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e.
****************************
var int1 = 1
var int2 = 2
function myfunction(){
int1++;
int2++;
}
myfunction();
****************************
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
Help!!
View Replies !
View Related
Help With XML Variables -- Arrays, Functions, Etc
I have been working on a Flash movie that loads variable data from an external XML file and dynamically displays the item names in a menu which may then be clicked to display other dynamically-loaded content that corresponds to the menu item that was clicked.
I have now come to a standstill in the project as there is something I'd like to achieve but simply cannot work out how. This is my first attempt at working with XML in Flash and one of my early attempts at using variables.
What I'm trying to achieve is; once the user has viewed the item's content, they can simply click "next" and "previous" buttons to display all of the content for the next or previous items in the XML document.
I know it probably sounds simple and I'm sure some of you could achieve this in 5 minutes (!) but I can't get my head around some of the coding. I assume previousSibling and nextSibling would come into play here as well as some sort of functions which access arrays of data for the previous and next items, but I'm just not sure how to correctly put these things to use.
Rather than post my code and example images of the stage up here on the forums, I've created an html page here: http://www.basemedia.com.au/hosted/help
Please, if you think you can be of any help, check it out. I would really appreciate it.
Thanks.
View Replies !
View Related
Class Variables In On Functions?
Hey, I was wondering if they found a better way of allowing the use of variables outside of an on function. For example in the script below I can use the variable bounds inside the target.onEnterFrame function because it's declared inside the constructer. However I can't use m_Bounds even though it's declared in the class.
ActionScript Code:
private var m_mcTarget:MovieClip; private var m_Bounds:BoundsData; function MotionHandler(target:MovieClip, bounds:BoundsData) { m_mcTarget = target; m_Bounds = bounds; m_mcTarget.onEnterFrame = function() { this._x = bounds.current.x; this._y = bounds.current.y; } }
I find it annoying and unorganized to redeclare variables from my own class just to use them in the onClick/onRelease/onEnterFrame etc.
If I were to move that onEnterFrame to a different function, I would have to provide a copy of the bounds var inside that function.
ActionScript Code:
private var m_mcTarget:MovieClip; private var m_Bounds:BoundsData; function MotionHandler(target:MovieClip, bounds:BoundsData) { m_mcTarget = target; m_Bounds = bounds; } public function Initialize():Void { var bounds:BoundsData = m_Bounds; m_mcTarget.onEnterFrame = function() { this._x = bounds.current.x; this._y = bounds.current.y; } }
In AS3.0 will they let us use class variables in on functions or are there any other methods?
View Replies !
View Related
Paths Functions And Variables
Hi!
I am having problems with a production I am making. Here's the description:
I have a variable in the _root called 'ordered'. I have another variable called 'total' inside a function called 'loadXML'. 'total' receives a number value from a node in a XML file correctly. I now want to transfer this value to the variable 'ordered' which, as I said, is in the _root.
However, 'total' is restricted to the function and I can't access it from the variable in the _root. Neither can I transfer the value from the variable in function to the _root.ordered, since such a line targets the _root of the function itself.
I guess this isn't too hard to solve, probably just a path issue, but I have a few rather large gaps in my knowledge of actionscripting. Can anyone help?
On the stage, there are three objects; a movieclip with the instance name 'clip', a movieclip with the instance name 'orderbox' and finally a dynamic text field with the instance name 'pos_txt'.
My code is on frame 1 and reads as follows:
Code:
System.useCodepage = true; // makes scandinavian charachters work.
// SET COUNTER
var kits = 500;
ordered = 486; // Just an initial value which is replaced later
var kitsleft = kits - ordered;
var counter = kitsleft;
//FUNCTION FOR COUNTER
loadXML = function (loaded)
{
if (loaded)
{
xmlNode = this.firstChild;
total = xmlNode.childNodes[0].firstChild.nodeValue;
//countertext = xmlNode.childNodes[0].childNodes[0].firstChild.nodeValue;
counterfunc(); // triggers function which loads value into dynamic textfield.
}
else
{
content = "file not loaded!";
} // end else if
} // End of the function
counterfunc = function() //Function that shoots the value into dynamic text field
{
pos_txt.text = 500 - total + " Tandvårdskit kvar"; // The text that is shot
_root.ordered = 500 - total; // tries to load value from xml variable "total" into "ordered"
} // End of the function
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("counter2.xml");
p = 0;
//CREATE MOVIE CLIPS
var col = 10; // # of columns
var row = 50; // # or rows
var allboxes = col*row; // # of MC's/cells in grid
var startX = 472 ; // horizontal starting position grid
var startY = 2498; // vertical starting position grid
var offsetX = -50; // horizontal offset
var offsetY = -50; // vertical offset
// RANDOM FUNCTION
Array.prototype.shuffle = function () {
this.sort(function () {return random(2) ;}) ;
} ;
// ARRAYS FOR STORING ORDERED AND REMAININGKITS
var orderedclipsArray:Array = new Array();
var remainingclipsArray:Array = new Array();
// MAKE THE GRID
for (i=0; i<allboxes; i++) {
duplicateMovieClip(_root.clip, "clip"+i, i);
theMC = _root["clip"+i];
theMC._x = startX+(i%col)*offsetX;
theMC._y = startY+Math.floor(i/col)*offsetY;
remainingclipsArray.push("clip"+i); //stores all movieclips in an array
}
//REMOVE ORDERED KITS FROM ARRAY
for (i=0; i<ordered; i++) { //actions below is based on the amount of ordered kits
remainingclipsArray.pop("clip"+i); //removes all ordered movieclips from the array and leaves the ones left
orderedclipsArray.push("clip"+i); //stores all ordered movieclips in an array
}
orderedclipsArray.shuffle(); // Shuffles the listed items in the array of ordered kits
//trace (orderedclipsArray);
//REMOVE ORDERED KITS FROM STAGE
for(i=0 ; i<ordered; i++){//actions below is based on the amount of ordered kits
removeMovieClip(eval(orderedclipsArray[i])) // removes the ordered kits from the stage
}
I also have an XML-file called counter2.xml with the following code:
Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<orderlist>
<orders>486</orders>
</orderlist>
View Replies !
View Related
Help Passing Variables Between Functions
Hi there,
I have been searching for what seems like weeks for an answer to this question, here is my problem:
I am building a flash photo gallery that is fed by an XML file, now I am fine with all of the XML things in flash, my problem comes when creating the thumbnail images onRelease event. Here is my code:
Code:
_global.counter = 0;
for (_global.counter = 0; _global.counter<itemArray.length; _global.counter++) {
//populate thumbnail array with URLS
thumbnails[_global.counter] = itemArray[_global.counter].childNodes[10].attributes.url;
//Populate images array with URLS
images[_global.counter] = itemArray[_global.counter].childNodes[7].attributes.url;
//Generate an empty movieClip for each thumbnail
grid_container_mc.attachMovie("thumbHolderID","thumb_"+_global.counter+"_mc",_global.counter);
//load in the thumbnail ur to the newly created movieClips
//grid_container_mc["thumb_"+_global.counter+"_mc"].loadMovie(thumbnails[_global.counter]);
//Set the _x & _y coordinates for the newly created movieclips
grid_container_mc["thumb_"+_global.counter+"_mc"]._x = ((_global.counter % 3)* xSpace);
grid_container_mc["thumb_"+_global.counter+"_mc"]._y = ((Math.floor(_global.counter/3)*ySpace));
//scale the thumbs
grid_container_mc["thumb_"+_global.counter+"_mc"]._xscale = scaleRatio;
grid_container_mc["thumb_"+_global.counter+"_mc"]._yscale = scaleRatio;
//create the onRelease events for the thumbs
grid_container_mc["thumb_"+_global.counter+"_mc"].onRelease = function(){
image_holder_mc.loadMovie(images[_global.counter]);
}
}
The problem is that when I release the mouse button I get a variable undefined error in the output window. I have researched and have found that my problem is that I can't pass a variable from the main function to the onRelease function, but am stumped as to how to get around this!
Any help any of you can give would be fantastic! This needs to be finished in a hurry and I am getting desperate....
I know its bad form to just use a forum to ask for help but I dont know what else to do!
Thanks!
View Replies !
View Related
Accessing Outside Variables From Functions
I can't figure out how to access variables that are declared in a movie clip from a function declared in that same movie clip.
i.e.
****************************
var int1 = 1
var int2 = 2
function myfunction(){
int1++;
int2++;
}
myfunction();
****************************
I'm trying to do this in the main movie clip of a movie that I plan on importing dynamically in another movie. I've tried to use this.int1++, but I think that flash was looking for a variable that belongs to "myfunction" when I did that. I could just use _root.int1++ but like I said, I plan on dynamically loading this into another movie, in which case it would be pointing to the wrong movie.
Help!!
View Replies !
View Related
Help With XML Variables -- Arrays, Functions, Etc
I have been working on a Flash movie that loads variable data from an external XML file and dynamically displays the item names in a menu which may then be clicked to display other dynamically-loaded content that corresponds to the menu item that was clicked.
I have now come to a standstill in the project as there is something I'd like to achieve but simply cannot work out how. This is my first attempt at working with XML in Flash and one of my early attempts at using variables.
What I'm trying to achieve is; once the user has viewed the item's content, they can simply click "next" and "previous" buttons to display all of the content for the next or previous items in the XML document.
I know it probably sounds simple and I'm sure some of you could achieve this in 5 minutes (!) but I can't get my head around some of the coding. I assume previousSibling and nextSibling would come into play here as well as some sort of functions which access arrays of data for the previous and next items, but I'm just not sure how to correctly put these things to use.
Rather than post my code and example images of the stage up here on the forums, I've created an html page here: http://www.basemedia.com.au/hosted/help
Please, if you think you can be of any help, check it out. I would really appreciate it.
Thanks.
View Replies !
View Related
Functions And Variables... Important Doubt
I have a script on a movieclip called movie01.
I want to load a function that I´ve created before.
The function is on the main timeline.
Take a look at the script below:
ex:
this is the script on the main timeline
Code:
function doit (target) {
target._y = 20;
target._yscale = work;
}
this is the script on a movie
Code:
onClipEvent (enterFrame) {
work = _x;
_root.doit(this);
}
When I call the function doit, does it understand the variable work?
I´m asking it 'cause the function is on a different path (main timeline), but it´ll be loaded inside the clip event handlers (_root.movie01).
Off course I can put the variable work inside the function doit, but I want to know if it works.
I may ask something like this too:
It will work like this?
Code:
onClipEvent (enterFrame) {
work = _x;
this._y = 20;
this._yscale = work;
}
Thanks
renato
View Replies !
View Related
Not Clear On Global Variables And Functions...please Help
Hi, I am trying to get a better grasp of global functions and variables. Please correct me if I am wrong.
First)
Global variables and functions are defined with a
_global.function ()
_global.variable=
Now, when a function or variable are named this way, you can just call the function or variable from any timeline WITHOUT having to resort to defining a path.
e.g. If I wanted to call a global function that was on the main timeline named "multiplier()" from an mc titled "first movie" I would just call it using "function multiplier()".
Correct? Can someone point me to a site, tutorial, etc. where I can learn more about it?
Thanks, if you help me, this is you...
Yeah, da' pimp.
View Replies !
View Related
Functions - Problem With Feeding In Variables
Hi there, here's a simple Flash problem I am having. Please take some time to help me out!
I have a function on the main timeline:
Code:
function move (v1, v2, v3){
m = (v1-v2)/v3;
v2 += m;
}
I am trying to call this from within a mc placed on the timeline called 'sq'.
In the 'sq' mc I have this code:
Code:
_parent.move(200, sq.sq_mc._y, 5);
'sq_mc' is a movieclip in the 'sq' mc and all I want to do is move its ._y with the simple inertia script.
How do I reference it? I know it works when it's not in a function. I've tried all these for var2:
Code:
_parent.sq.sq_mc._y
_root.sq.sq_mc._y
sq_mc._y
None work! What is going on?
Many thanks for your time,
Neil
View Replies !
View Related
Variables, Functions, Timelines & Scope
I have some variables declared on the root timeline.
var a, b, c;
In a nested movie (loaded into a placeholder mc from the root via loadMovie), I have a function:
function foo(){
a = 100;
b = undefined;
c = "yes";
createEmptyMovieClip("myMovie_mc", 0)
myMovie_mc.loadMovie("usesVariables.swf")
}
In the movie "usesVariables.swf" I have the following code:
createEmptyMovieClip("box_mc", 0)
box_mc._x = _parent.a; //THIS REFERS TO THE VALUE OF a DECLARED IN THE FUNTION "foo". DOES THIS VARIABLE STILL REPRESENT THE VARIABLE "a" DECLARED ON THE ROOT MOVIE?
}
Big picture question is this: Is this a proper technique for utilizing and managing variables? The idea is to allow the "usesVariables.swf" movie to serve many purposes by allowing the calling movie to determine its appearance and properties.
View Replies !
View Related
Passing Variables To Functions Like Javascript?
Back in my days as a DHTML developer, I'd routinely pass variables to functions using javascript.
i.e.
*function call*
myFunction('num1')
*function*
myFunction(theVariable){
eval("this." + theVariable + ".doSomething());
}
When I try to do something similar in Actionscript, nothing works. Is there something similar to eval that I could use? See flash example below:
*function call*
doThis('lg_r5_3');
*function*
function doThis(theVariable){
"_root." + theVariable + ".scaleTo(100, .25, 'easeinoutquad' 1.5)";
}
Any help would be appreciated. Many thanks in advance!!
View Replies !
View Related
Functions And Variables Not Recognized Throughout Program
Hello, I am experiencing a little problem with functions and variables not being recognized throughout my program in MX. Here is the situation:
I have a function in the code in Layer 1 that works perfectly when it is called via a button click. That’s all and well, but I need it to be running constantly.
I tried calling the function in “onClipEvent (enterFrame)”, but the function, or any function for that matter, is not actually called.
I know that I can put code directly into “onClipEvent (enterFrame)”, but then (for some odd reason) the variables from the function’s code are not recognized.
How can I get the function to run continuously? I don’t mind if I have to copy and paste the code, as long as it works.
A MUCH simplified example:
Layer code:
code:
function GoTest() {
if (Running == true) {
Ball._x += 10;
}
}
Button code:
code:
on (release) {
Running = true;
GoTest();
}
MC Ball code:
code:
onClipEvent (enterFrame) {
GoTest();
}
If I click on the button, the Ball moves, which sets Running to true and theoretically should make the ball move every frame. However, the Ball stays still.
Any ideas?
Thanks,
EngineerDave
View Replies !
View Related
Problems With Functions And Variables HEEELLLPP
I've a very big problem:
I define a function in an external "scripts.as" file like that:
function dosomething(par1:String,par2:Number)
{
...
trace("|"+par1+"|"+par2);
}
then I create a new movie clip and on frame 1 i write:
#include "scripts.as"
var p:String;
var n:Number;
p="hello";
n=100;
dosomething(p,n);
output isn't "|hello|100", it is "||" and I don't understand why I can't pass parameter values
help me please!!
View Replies !
View Related
|