FORUMS: list search recent posts

Animating 0's and 1's

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Tony Westerfield
Animating 0's and 1's
on Feb 13, 2010 at 9:30:19 pm

I am looking for a simple, elegant way to randomly generate 0's and 1's in a line on stage. I am simulating one computer talking to another. Aside from creating it with brute force (typing 0 and 1 randomly and copying/pasting frame by frame), is there an actionscript or tutorial for this?

Thanks

Tony W


Return to posts index

demetri tashie
Re: Animating 0's and 1's
on Feb 13, 2010 at 10:28:30 pm

i don't hink there is a turorial for specifically this, but the code shouldn't be to hard to write.

i would suggest to create separate dynamic text fields for each number you want. position them in a line or whatever you want.

for instance have 5 dynamic text fields, named text1,text2 through text5.

i would then put them in an array, then access the array to populate the text fields. you take advantage of the Math Class to a) generate random numbers and b) make sure it could be only a 0 or a 1.

here is some code that would accomplish that based on a click of a button.
i hope that helps, and gives you ideas how to approach your problems. i am not gauranteeing it is the most 'elegant' way to do it ....

var textArray:Array = [text1, text2, text3, text4, text5];

text_btn.addEventListener(MouseEvent.CLICK, addText);
function addText(evt:MouseEvent):void {

for (var i:uint=0; i<5; i++) {
var ranNum0:Number= Math.random()*1;
var ranInt0:int=Math.round(ranNum0);
textArray[i].text=String(ranInt0);
ranNum0=Math.random()*1;
}
}



Return to posts index

demetri tashie
Re: Animating 0's and 1's
on Feb 13, 2010 at 10:40:01 pm

here is a quick, down and dirty example of it in action:
http://www.demetri-media.com/FlashTalker/textArray.swf

if you want or need example .fla let me know


Return to posts index


Tony Westerfield
Re: Animating 0's and 1's
on Feb 13, 2010 at 11:45:49 pm

Thanks Demetri. An example .fla would be great. The mouse event is fine, but I wanted the 0101's to automatically generate. No interactivity.

I created 5 dynamic text fields on one layer. All are properly named. I cant get past one set of number, though.



Tony W


Return to posts index

demetri tashie
Re: Animating 0's and 1's
on Feb 14, 2010 at 2:03:27 am

OK - here is a .fla that actually has 15 text fields. change or omit them at will - just make sure to adjust the Array accordingly. I commented out the code causing the numbers to be generated by a button click. it will now just automatically generate on publishing.

it should make sense. if not, just ask.


549_textarray.fla.zip


Return to posts index

Tony Westerfield
Re: Animating 0's and 1's
on Feb 14, 2010 at 3:03:25 am

Perfect! Big time thanks.

Tony W


Return to posts index


Tony Westerfield
Odd?
on Feb 14, 2010 at 4:05:18 pm

One more thing. When I try to rotate an instance of the 0101 movie clip on the stage, the numbers disappear! Nothing when I test render either. Ans, there is no way to create a SWF and import as a "pre-rendered" element.

Why is this?

Tony W


Return to posts index

demetri tashie
Re: Odd?
on Feb 14, 2010 at 4:15:50 pm

dynamic text and input text doesn't render rotated like that. i'm not the one to explain why, i just know
it 's behavoir.


Return to posts index

Tony Westerfield
Re: Odd?
on Feb 14, 2010 at 4:24:31 pm

So I need to figure out a way to create this without dynamic text. Is there a way to tag the static text type with its own name that actionscript can reference? I have already tried creating a symbol of each text item and naming the instance text1, text2, etc. No dice.

Tony W


Return to posts index


demetri tashie
Re: Odd?
on Feb 14, 2010 at 4:30:38 pm

probably not. static text, by its very nature is, well, static - it doesn't change, and isn't referenced by AS.

you might be trying to over-reach. however, off the top of my head, there are things i might try- but it would be complicated. is this being used on the web?
if so i might have the text HTML text, and see if it is possible through a javascript/actionscript combo to change the text. might work. might not....

what are you fully trying to do? maybe we can think of a work-around for it.


Return to posts index

Tony Westerfield
Re: Odd?
on Feb 14, 2010 at 4:38:58 pm

The numbers will automatically generate in a random order. 0101001110101 will continuously change or animate. I think I will just use brute force with this one and copy/paste frame by frame, changing the 0101 combination per frame.

Tony W


Return to posts index

demetri tashie
Re: Odd?
on Feb 14, 2010 at 4:44:28 pm

oh no- don't do that.


you can user either a Timer, or an EnterFrame to continually update it if that is waht you are trying to do.

give me a few minutes and i'll come up with an example.

are you doing this frame based ( on a time-line ) or not ?


Return to posts index


demetri tashie
Re: Odd?(with example)
on Feb 14, 2010 at 4:56:58 pm

ok- fairly easy using a Timer. you can see the example here:
ww.demetri-media.com/FlashTalker/textArray2.swf

here is the code. you can drop this into the .fla that i provided before to test it out. i do have it initialized by the button click - but you can disable that and just have it run automatically.

if you are not used to Timer events, the 2 parameters passed into it are seconds ( i used 500 which is half a second. 1000 = 1 second) and the # of times to loop ( i used 50 just so it will stop. omitting this parameter will keep it looping indefinitely). so my Timer will update every half second for a total of 50 times. adjust as you see fit.

var textArray:Array = [text1, text2, text3, text4, text5,text6, text7, text8, text9, text10,text11, text12, text13, text14, text15];

text_btn.addEventListener(MouseEvent.CLICK, addText);
function addText(evt:MouseEvent):void {

var myTimer:Timer = new Timer(250, 50);
myTimer.addEventListener(TimerEvent.TIMER, updateFunction);
myTimer.start();

function updateFunction(evt:TimerEvent):void{
for (var i:uint=0; i<15; i++) {
var ranNum0:Number= Math.random()*1;
var ranInt0:int=Math.round(ranNum0);
textArray[i].text=String(ranInt0);
ranNum0=Math.random()*1;
}
}
}




Return to posts index

Tony Westerfield
Re: Odd?
on Feb 14, 2010 at 5:01:06 pm

Frame-based. Here is an example of what I am creating. Click over two presentations to "service virtualization" and note the 0101's.

Thanks.

Tony W


Return to posts index

Tony Westerfield
Oops, forgot the link...
on Feb 14, 2010 at 5:01:47 pm

http://www.tibco.com/software/soa/default.jsp


Tony W


Return to posts index


demetri tashie
Re: Oops, forgot the link...
on Feb 14, 2010 at 5:16:31 pm

i tried the link, and went to the clip, but didn't see the 0's and 1's.
never mind.

if those text fields are on the first frame, and you just carry them over the length of the frames you want them to be seen, then this code will work ( i disabled the button information)
i have the numbers updating real fast, and looping 500 times.

just change the Timer parameters depending on the length of your timeline, and how fast you want them to update.

var textArray:Array = [text1, text2, text3, text4, text5,text6, text7, text8, text9, text10,text11, text12, text13, text14, text15];

//text_btn.addEventListener(MouseEvent.CLICK, addText);
//function addText(evt:MouseEvent):void {

var myTimer:Timer = new Timer(20, 500);
myTimer.addEventListener(TimerEvent.TIMER, updateFunction);
myTimer.start();

function updateFunction(evt:TimerEvent):void{
for (var i:uint=0; i<15; i++) {
var ranNum0:Number= Math.random()*1;
var ranInt0:int=Math.round(ranNum0);
textArray[i].text=String(ranInt0);
ranNum0=Math.random()*1;
}
}
//}



Return to posts index

Tony Westerfield
Re: Oops, forgot the link...
on Feb 14, 2010 at 5:20:51 pm

Thanks for your help Demetri. Much appreciated!

Tony W


Return to posts index

demetri tashie
Re: Oops, forgot the link...
on Feb 14, 2010 at 5:24:03 pm

my pleasure.
let us know when you have it running as you want, so we can see your work !



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]