Code To Determine Integers
hi there, I've been working on a site where I have a hit count in flash and i've got that working but the bit I'm stuck on is that I need that number generated by the hit count to determine what parts of an animation are playing. These separate animations are numbered 1-9 and I want the code to determine whether they play by whether they are a factor of the hit number initially generated. So 1 is always played and I imagine that the code would work something like this; if count/2=integer gotoAndPlay() if count/2=not an integer gotoAndPlay() for each number 2-9
Is there a piece of code that could do this? the only things I can find about integers involve rounding up numbers. I've been using flash for a few months now and I think I'm a bit out of my depth, but it seems like it could be quite easy!
cheers,
SitePoint > Design Your Site > Flash and Actionscript
Posted on: Jan 26, 2006, 08:53
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Code To Determine Complete
I am using flash 2004 pro and i do not know code that well.
i have made a crossword puzzle and it can be completet non-linearly.
so i need a point in the right direction, if there are multiple tasks how would i make something detect if those tasks were complete to move on to something else?
thanks
casey
Strings, Integers...
I'm loading a variable (numberofproj) from a external txt file into Flash, which should duplicate a MC a set number of times according to the value of numberofproj
It reads it as a string so I convert it to a integer
by using this:
numberproj = Number(numberofproj);
Then my duplication sequence is as follows:
while (numberproj>=1) {
duplicateMovieClip "_root.project", "_root.project" add numberofproj, numberofproj);
setProperty ("_root.project" add numberofproj, _visible, "true");
numberofproj = numberofproj--;
}
This doesn't work. I've tried replacing the add with & and even &&. Can someone help me?
Forcing Integers
Whats up, yall --
Okay, i've got this cool interface that allows you to play through an MC's frames by dragging a slider. it works by calculating the _y of the slider and going to the corresponding frame. Works great, but could use a little adjustment --
Ok, the movie is 30 frames and the slider's range is 60. So I divide the _y by 2 in order to go to the right frame, right? The problem is on odd numbered heights I end up with a value thats a decimal, and there is no frame "3.5," you know? Is there any way to force the result of the equasion to be an integer? For now I just made my 30 frame MC have 60 frames. Thanks --
Figuring Integers
does anyone know an easy way to check if a number is an integer in an if statemet. eg: if (number == int) [ blah blah]
Loading Integers
Im trying to load a number from a txt file to use in an equation .... but it seems when I loadvariable, it thinks of it as text instead of a number, and therfore does not work.
Is there a way to convert or a workaround ?
TIA
Scroll By Integers
hi,
i have a scroll bar (flash component) which i need to make only scrollable by integers (text in pixel font inside. anybody can give me some help?
thx,
nolas
[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; ?
Random Integers
I have been playing around in flash trying the random code out but I don't seem to be doing it right.
What I want to do: Have flash play through and at a certain frame create a random integer (either 1 or 2) and place it in a variable. ThenCheck that variable and if it's 1 gotoAndPlay(certainframe) and if its 2 gotoAndPlay(anotherframe).
Here's what I had tried. On a frame i put
Code:
number=random(2)
if(number=1){
gotoAndPlay(#);
}
if(number=2){
gotoAndPlay(#);
}
But, it seemed to always gotoAndPlay the second #. I tried it over 30 times and even had a box showing the variable and no matter what it went to the second frame #. I guess I just don't know what to put to make this work. Not much work with random scripts so can anyone help me out?
Random Integers
I have been playing around in flash trying the random code out but I don't seem to be doing it right.
What I want to do: Have flash play through and at a certain frame create a random integer (either 1 or 2) and place it in a variable. ThenCheck that variable and if it's 1 gotoAndPlay(certainframe) and if its 2 gotoAndPlay(anotherframe).
Here's what I had tried. On a frame i put
Code:
number=random(2)
if(number=1){
gotoAndPlay(#);
}
if(number=2){
gotoAndPlay(#);
}
But, it seemed to always gotoAndPlay the second #. I tried it over 30 times and even had a box showing the variable and no matter what it went to the second frame #. I guess I just don't know what to put to make this work. Not much work with random scripts so can anyone help me out?
Dynamic Text Whole Integers?
I have a scrolling dynamic text field and I am using a pixel font with it. The problem is that the text is blurred. I would like to know what i have to do to stop it on whole integers so the text stays crisp.
Thanks very much
Attaching Integers To Movieclips
Say for instance i had a rectangle and a circle, both movie clips, and i wanted the circle to be 1 and the rectangle to be 2, is there a way of attaching a number to this graphic using actionscript, so that if i was sending data from flash thru an xml socket into a program that accepts raw data i could recieve these numbers, by maybe making another vector graphic to listen for events or recognise these MC's with a script that knows the internal value of them? Does this make sense? basically can i "tag" for want of a better word symbols with number values?
Change Alpha Using Integers
I have a simple script that fades a MC in or out.
All I want to do is decrease the alpha gradually by .1.
But it seems to be decreasing by many decimal places, rather than just -.1;
Is there a way to use only whole numbers like .8 as opposed to .723342?
Thanks, all.
Example:
var fade:Number = -.1;
box_mc.alpha += fade;
Converting Integers To Strings
Hi all,
I'm trying to convert an integer value into a string so that I can then manipulate the individual characters and am having problems! My current code is something like the below:
---------------------------------------------------
_global.hundreds = 0;
_global.tens = 0;
_global.units = 0;
_global.tenps = 0;
_global.unitps = 0;
_global.credits = "";
var money = 542.19;
var credStr:String = "";
credStr = money;
_global.credits = credStr;
---------------------------------------------------
I don't know if it's necessary or not, but I used local variables to pass the information into the _global variable as I wasn't sure if I could specify the data type in a _global variable?!
Suffice to say, this isn't working. It doesn't seem to want to convert the number into a string whatever I do!
FYI the following code is what is supposed to happen to the string once it is converted:
---------------------------------------------------
if (_global.credits.length < 6) {
if (_global.credits.length == 5) {
_global.credits = "0"+_global.credits;
}
else if (_global.credits.length == 4) {
_global.credits = "00"+_global.credits;
}
}
var fc:String = _global.credits.charAt(0);
var sc:String = _global.credits.charAt(1);
var tc:String = _global.credits.charAt(2);
var fc2:String = _global.credits.charAt(4);
var sc2:String = _global.credits.charAt(5);
fc++;
sc++;
tc++;
fc2++;
sc2++;
_global.hundreds = (fc);
_global.tens = (sc);
_global.units = (tc);
_global.tenps = (fc2);
_global.unitps = (sc2);
---------------------------------------------------
I have tested this by passing the value in as a string in the first place and it works perfectly - so it's just the conversion where I am not getting this right :(
Any help with this would be greatly appreciated!
Thanks, Richard
Edited: 06/13/2007 at 06:36:10 AM by tricky_ricardo
Loading Integers From XML File.
Hello
I'm loading an XML file into flash, one of the fields is an ID of them item in the database the XML file was made from.
I can load everything fine and have put all the data into a multi-dimensional array, but for some reason the ID is a string. I've tried using Number(myID), to covert it to an integer but nothing seems to work.
So how can I load an Integer into Flash using XML and have Flash recognise it as an Integer?
I'm using Flash MX '04.
Cheers
Ric
Integers To English Conversion (PHP)
Hey,
I wrote this little script to convert any integer greater than 0, and less than a decillion (10^33, but there are probably php integer limitations).
PHP Code:
<?php
function makeNumberEnglish ($number) {
// Variables
$phrase = '';
$number = (string) $number;
$values = array();
$words = array();
// Fill integers array
for ($i=strlen($number)-1; $i>=0; $i-=3) {
$values[pow(10,strlen($number)-($i+1))] = (int) substr($number,($i>2)?$i-2:0,($i>2)?3:$i+1);
}
// Places and replacements (backwards to catch largest first)
$places = array_reverse ( array (
1, 1000, 1000000, 1000000000, 1000000000000, 1000000000000000, 1000000000000000000,
1000000000000000000000, 1000000000000000000000000, 1000000000000000000000000000,
1000000000000000000000000000000
) );
$placeReplacements = array_reverse ( array (
'', 'thousand', 'million', 'billion', 'trillion','quadrillion','quintillion','sextillion',
'septillion','octillion','nonillion'
) );
foreach ($values as $place => $numeral ) {
$placeWord = str_replace($places,$placeReplacements,(int) $place);
if ($numeral!=0) {
$words[$place] = makeHundredsString($numeral) . ' ' . $placeWord;
}
}
$words = array_reverse($words);
$phrase = array_shift($words);
foreach ($words as $word) {
if ($word!='') {
$phrase .= ', '.$word;
}
}
return $phrase;
}
function makeHundredsString ($number) {
if ($number >= 1000 || $number < 0) // Get rid of invalid calls
die ('makeHundredsString() may not recieve a number greater than or equal to 1,000, or less than 0.');
$words = array(); // Hold words to be concatinated
$phrase = ""; // String to concatinate words to
$number = str_pad((string) $number, 3, '0', STR_PAD_LEFT);
$numString = (string) $number;
$digits = array ('', 'one','two','three','four','five','six','seven','eight','nine');
$tens = array ('','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety');
$teens = array ('ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen');
for ($i=0;$i<3;$i++) {
$words[] = ($i==1)?$tens[$numString{$i}]:$digits[$numString{$i}];
}
if ($words[1] == 'ten') {
$words[2] = $teens[$numString{2}];
$words[1] = '';
}
// Make sure it is very natural
$phrase = (($words[0]=='')?null:$words[0].' hundred ').
// If number has hundreds place, add it
(($words[0]!=''&&($words[1]!='' || $words[2]!=''))?'and ':null).$words[1].
// If number had a hundreds place, and has either ones or tens too
(($words[2]=='')?null:(($words[1]!='')?'-':null).$words[2]);
// If number is not blank: if tens place is not blank, then put dash,
// else null, then concatinate ones place
return $phrase;
}
?>
Execute it using something like this:
PHP Code:
<?=makeNumberEnglish(522);?>
In a minute, I'll try making an html form for y'all to test it out without running it yourself.
[math] Bytes To Integers
Hi, guys.
Is there an easy way to convert bit flags into their integer values? My brain is a bit wobbly at the moment.
The bits would be “strings”...
From "010" to 2
From "101" to 5
From "111" to 7
...and so on.
Flash And Integers/ Arrays :(
I have an array with the following in:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 512 1231 763 167 1624 736 3243 643 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I am trying to find the highest num, I am using the code below:
but it keeps returning 763 as the highest.
Code:
var High = 0;
for(i=0;i<=GCount.length;++i)
{
text = text + GCount[i] + " ";
if(GCount[i] > High)
{
High = GCount[i];
}
}
Thanks
From Text File Into Array & Integers
External Text file
task1=10,20
Code
task1=task.split(",");
How do I get the split values into a array? I've tried EVERYTHING. This is annoying the hell outa me. PLEASE HELP
Scrolling Pixel Fonts On Whole Integers - Help
Hi -
I would like to know how to scroll a pixel font and have it stop on a whole integer value on a roll out function.
I keep finding posts that say you SHOULD do this but I can't find a post or tutorial that says specifically how.
I emailed fontsforflash and they suggested I post an inquiry here, which wasn't very helpful but I'm hoping someone here will be.
My knowledge of ActionScripting is still fairly beginner so please be as specific as possible.
My current code for the scroll action (which works fine on antialiased fonts) is:
on (rollOver) {
tellTarget ("/upaction") {
gotoAndPlay ("up");
}
}
on (rollOut) {
tellTarget ("/upaction") {
gotoAndStop ("stop");
}
}
The down action is similar:
on (rollOver) {
tellTarget ("/scroll") {
play ();
}
}
on (rollOut) {
tellTarget ("/scroll") {
stop ();
}
}
The text itself is a movie clip scrolling behind a mask.
Also, if anyone has any tips to add to this on easing the stop action for a smooth stop that would be really nice too.
Thanks in advance!
Convert Integers To “US Numeric Format”?
Dear Falshkitters,
Will somebody be able to help me to find a script that allows to convert integers to “US numeric format”? That is, it converts 1000000 to 1.000.000, it converts 1200 to 1.200, etc.
Thank you very much in advance for your help.
Vahagn
How To Check An Integer Against A Range Of Integers
Hello,
I am trying to do something fairly basic and can't get my ahead around how to do it. I need users to be able to find their local store by entering a zip code. I have a list provided to me that has a range of zip codes with the nearest store, so I want to do it like this:
A user enters "01003" and the app sees that since any number between 01001-06999 is Boston area (the numbers that divide the ranges are in sequential order), it brings up Boston.
Can someone please help direct me towards putting this in code? I assume it has something to do with a "for" loop, but I'm a designer in over my head... and it hurts.
Nate
Associative Array With Unsigned Integers
Hello guys!
I have an associative array that is used in a special way: its keys are IDs as unsigned integers, but their order is random and some IDs are large numbers. That's why I have used an associative array. So, 2 questions:
1) Is this ok to use associative arrays this way? Because all I've read about associative arrays is that you usually use them with strings or objects, not int.
2) Is it fast to retrieve a value, given the key? Is it really hashed to be fast?
Thanks a lot!
Barbara
Variable Types: Integers Vs Strings?
K so I got a number input from a input field and I guess that's in a string form, because when I add a number to that variable, I got the wrong answer.
input = 6
input + 1 = 61
Help me convert the input into an integer, so that I can use it in equations!
Preloader To Display Percent In Integers?
The code below is displaying percent loaded to around 15 decimal places.
The clip I'm loading is huge, so the preloader displays things like:
"Loaded: 0.16263623667762%"
Yeesh. Is there a way to get it to display "Loaded: 1%"
Thanks!
Rick
onClipEvent (load) {
_root.stop();
this.topScale = this._width;
this._xscale = 0;
ft = int(_root.getBytesTotal()/1024);
}
onClipEvent (enterFrame) {
fl = int(_root.getBytesLoaded()/1024);
this._xscale = Math.floor((fl/ft)*this.topScale);
_parent.mytext.text= "LOADING: "+(fl/ft)*100+"%";
_parent.mytext.setTextFormat(_parent.mtextFormat);
//_parent.llt = "LOADING "+fl+" KB OF "+ft+" KB";
if (fl == ft) {
_root.gotoAndPlay(_currentframe+1);
play();
}
}
Ensuring Integers In Input Text Field
I'm developing flash program that creates a bar chart based on user input data. The coding to scale the bar to the proper height is done, but I'd like to add error messages (This is designed to be used by executives and managers so it has to be idiot-proof.)
The user has to type in a numerical value for the minimum, maximum and charted values.
Possibility one: Alter the insert text field to only accept numbers. Any way to do this?
Possibility two: Is there a statement that asks "Is this variable an integer?" That way I can use an 'IF' statement to jump back to load an error message and jump back to the insertion frame.
Possibility three?
Thanks in advance!
How To Display 3 Integers For Percent Loaded In Preloader?
i'm sure this is easy, but i can't figure it out.. i can do the normal display of percent loaded in a preloader where it starts at 1 and increments up to 100, but how can i have it start at 001 and increment up to 100
if i use this normally, what would i have to change to constantly display 3 integers while loading?? :
Code:
// this occurs within an onEnterFrame , i just don't feel like writing the whole code out
...
percent = (_root.getBytesLoaded()/_root.getBytesTotal())*100;
percentText = Math.ceil(percent); // +"%"; normally this would come after percent
any ideas?.. i'm sure it's easy.. i just can't figure it out. Probably something like
Code:
if (percent < 10) {
percentText = "00"+Math.ceil(percent);
} else if (percent > 10 && percent < 100) {
percentText = "0"+Math.ceil(percent);
} else {
percentText = "100";
}
there just has to be a more logical/easy way to write it (by the way, i just thought that up as i was writing this.. so i'll test it and let you know if it works or not while i wait to see if anyone has a better way...
Dynamic Text Field, Integers And Masks
I have a very odd problem here. But first let me set the scene...
I have a site which im developing entirely in Flash. Although I have some experiance with flash i have never ventured further than dots which follow the mouse or the odd tween etc.
This project ahs taught me ALOT; everything from loading multiple movies into a scene and handling XML along side that ive picked up some nifty Apache ReWriteRule tricks which are proving wonders for integrating the site with PHP and MySQL (somethihng I can actually do well!)
Anyway, enough blabbering.
On my root movie (as in the movie which calls all the others) I have a little dynamic text field at the bottom for displaying my telephone number and address.
The content is pulled in via HTML and the whle thing is masked.
Now. When I preview just the SCENE itself everythign works hunky dory and looks verrrrry sexy
BUT when i export the entire movie (version checkers, preloaders, intro and main content itself) a very odd thign happens... all the numbers dont show up! The characters are fine but its as if all the numbers have beend ropped somehow. but only when i view the entire movie from begginning to end.
I've tried embedding the font and still nothing.
Any one experienced this before or know what might be going wrong?
Im thinking its something to do with the first 3 scenes, but all the code in there seems fairly simple?? is there a conflict?
I'll post code if anyone can suggest what code to publish as I'm not terribly sure exactly what should be published.
Many thanks
Pablo
Sending Integers With Image Loading Events
Hello,
I'm trying to load more than one image using action script 3 code. I'd like to send with the loading event of the image with an image Id number. That way, when Event.COMPLETE event arrives, I will be able to know which image the event belongs to according to that image Id. Is that possible? How?
Thanks!
Loading Numeric Variables Form Php/ Converting To Integers
I'm facing some problem's using numeric variables from Php. The variables are loaded correctly. But when try to compare these values to other values in a while statement, flash uses them as if they where strings. I tried the int() statement to convert the strings to numeric values again, but this doesn't work. Can anyone help me out on this one. Probably I have to use Number() or Number.valueOf() statement, I also tried these already but perhaps in the wrong way. Thanks in advance,
Cheers,
~Shaman~
Movieclip Not Moving To "whole Integers"
Hi, could someone please check out my fla.
I have this movieclip that slides around to different positions when buttons are pressed, and I have give the clip specific positions to go to.
When I trace to see if the clip is gonig to the right positions I noticed that it never lands on whole integers (always .5 off?!!)
Why is this happening and is there any easy way to solve this?
any help much appreciated
thanks
Chris
How To Determine The End Of A Loaded SWF
I am loading an SWF into an empty movie clip in scene 1.
Scene 1 has only one frame. I would like to advance to the second scene after the loaded SWF finishes its animation.
How can I determine the end of the SWF so that I can move on to the second scene?
Thanks in advance for anyone with ideas.
Variables To Determine The URL... How?
I am creating a Bible Research site that will allow people to compare different versions of the Bible side by side with other versions of the Bible.
Here is my problem...
In the flash I have 3 things that the user inputs...
Version (version of Bible, NIV, KJV)
Book (Genesis, Exodus)
Chapter (1,2)
Now there is also a button that activates the search and gets the page. It is titled "research"
Now when you click research it needs to get a URL. The URL is supposed to be this...
/(Version)/(book)/(Chapter).html
or here is an example
/NIV/Genesis/1.html
Now how do I make the Get URL command to read all 3 variables to determine the URL?
Any help woudl be appreciated... thanks
How Does One Determine What Size
I am just starting to think about my first Flash web site. Flash has a default of 400 x 550. For the web to be viewable nicely on a web page, what is a good size to set the stage?
Thanks!
Determine Bandwidth?
I'm trying to figure out how to determine the bandwidth of a visitor so that I can route them to an appropriate file for their bandwidth from WITHIN the flash file.
Anyone know a site where I can learn this?
Load .swf - How Determine Which Swf Is Above Which?
Hello again,
it seems i've found what i was surching for... the answer of my earlier thread concerning loading and uploading was:
loadMovieNum ("something.swf", 1);
This allows me to load a swf into a main swf! Up to here great! But what are the levels - the "1" in the script here above. In fact my second swf loads above the main but should be under. What can i do?
Determine SWF Played Once
I am looking for a script that can be used to determine if an SWF file has been played or not.
We want it to be played once on the first visit to the site and when a user returns on the same day it would either load another file or have a 'Play Again' button in the swf file...
Going to update the swf every few days or even daily on a basis.
Any suggestions?
How To Determine Maxscroll?
I am using Flash MX (on Mac OS 10.3 if that makes any difference).
How do i get teh maxscroll value of my dynamic text boxes?
Each time i use the trace method i ALWAYS get a return value of 1.
I am stuck
Please unstick me
Thanks
Determine When .jpg Loaded
Hi there,
I have used the function LoadMovie to load an external .JPG to a target movie clip instance in my flash.
Is there any way that I can determine when the external .jpg has finsihed loading into flash before I contine to the next frame?
Thanks!
(using MX2004)
1st MC Able To Determine Position Of 2nd MC
I've searched all over the forum but I couldnt' seem to find the answer.
What's the variable for one Movie Clip to find the position of another Movie Clip?
Such as
If (_root.hero x position < enemy)) {
do this ()
I'm using flash mx btw.
Thanks in advance
Determine Source FLA Of SWF?
More legacy code woes...
I have a number of SWFs, and multiple FLAs (from various SourceSafe versioning branches) which may have created them. I need to know which particular FLA "version" built which particular currently-used SWF. The previous team was out of control so it's not unusual to have 5 or 6 FLAs that all claim they built a certain SWF. (I particularly like "player_john.fla" and "player_bob.fla", both in the same folder, both pointing to the same SWF file, both with similar save dates, and both with same functions, but radically different code. Welcome to my wonderful world! )
Short of publishing every single FLA and doing a byte compare on the results (and even that's not accurate) does anybody know of an easy way to determine which particular FLA actually built the SWF I'm currently using?
The best idea I've come up with so far is loading the swf into an empty movie, and running a debug to get all the objects and functions, and then openeing up each FLA and comparing them. Tedious, and not always guaranteed.
I know the FLAs tend to store physical pathnames of where they were when they were built, so I'm hoping maybe there's some kind of identifer that also get compiled into the SWF???
Determine Path To Swf
Hello,
Is there a way to determine if the swf file is playing back from a local file:/// or server http:// location in AS3??
Happy Thanksgiving!
cheers,
frank grimes
How To Determine Type Of FLV
I am working on a project where I am receiving FLV files from a client to integrate into a Flash application.
The FLV files should have transparency but they do not. I am guessing that the client encoded them (exported from After Effects) with the codec set to Sorenson Spark, rather than On2 VP6 -- which is what we need. So I want to verify this and see if that is the problem.
However, I haven't seen any tool in Flash that will report the codec of the existing FLV. Can someone tell me how this can be done, either in Flash or with a 3rd-party tool?
thanks,
BR
|