May 25, 2013, 11:23:12 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Prowlie Welcome back! The site migration is complete and normal service resumed.
Advanced search
Pages: 1 2 [3]   Go Down
Print
Author Topic: What Does this button do? AS3 Help  (Read 9364 times)
0 Members and 1 Guest are viewing this topic.
TheGrayK
That Awesome Guy You Know
Senior Member
****
Offline Offline

Gender: Male
Posts: 907

Daredevil Extraordinair!


« Reply #30 on: October 14, 2009, 05:56:41 AM »

I was unaware that I could do that thank you that helps out a lot thanks. Shocked
Logged

The novelty of my own mortality has yet to be torn,
While the vulgarity of my existence has made its welcome worn.
TheGrayK
That Awesome Guy You Know
Senior Member
****
Offline Offline

Gender: Male
Posts: 907

Daredevil Extraordinair!


« Reply #31 on: December 23, 2009, 09:16:48 AM »

Hello Programmers!
It has been awhile since I've done any actionscript so it may seem like I know less than I did before (if that is the case it is as it seems) .
But I am in need of a swarming particle effect (sort of like those little white flies on "Waterlollies") .
I dont know where to start even I am practicing some stuff right now but not succesfully.
I will update as I get further if I get further.
I'm not asking for someone to code this for me but just for a little help getting there myself that is all.
Please and thank you for helping and trying to help.
If you can't help thank you for giving me the time of day and stopping to read this.

Many Many Thanks ~ Kris (TheGrayK) Gray

Edit:
Ive started with making two new Symbols one named bug which I have set as a graphic symbol and the other titled swarm which i plan on using for the AS now I have no Idea how to go about making the Bug symbol travel within a limited area but also keep it as random a path as possible if that makes sense to anyone. but I will update when more is done.
« Last Edit: December 23, 2009, 09:25:54 AM by TheGrayK » Logged

The novelty of my own mortality has yet to be torn,
While the vulgarity of my existence has made its welcome worn.
supermoose
Full Member
***
Offline Offline

Gender: Male
Posts: 240


Yes. I beat IWBTG. Only took ~60 hours of play.


« Reply #32 on: December 23, 2009, 10:09:04 AM »

We actually just upgraded a swarm effect to AS3 in another thread, you may want to check it out.
http://www.biteycastle.com/smf/index.php/topic,2074.0.html

For a problem like this, it is best to break the problem down as simply as you can.
What do we need to do to manage a swarm?
-Spawn bugs
-Move every bug in a random direction, at a random speed
-If a bug is outside of the area you want it to be, turn around, or teleport back to the edge

use the new bug() command inside the spawn the right number of bugs

Basically, the way to get the "contained random" effect that you saw previously is by using Math.random() to determine the direction and speed.  This can get redefined as often as you like.  The current script uses a variable called *jitter* to determine how often a bug should change direction.

Then, you add in a few if statements that say *if a fly gets beyond X pixels of the centerpoint, turn around.*

Hope it helps, without giving too much away.
Logged

TheGrayK
That Awesome Guy You Know
Senior Member
****
Offline Offline

Gender: Male
Posts: 907

Daredevil Extraordinair!


« Reply #33 on: December 24, 2009, 02:11:36 AM »

Thanks This is some tough crap but I'm glad that I'm learning.
Logged

The novelty of my own mortality has yet to be torn,
While the vulgarity of my existence has made its welcome worn.
TheGrayK
That Awesome Guy You Know
Senior Member
****
Offline Offline

Gender: Male
Posts: 907

Daredevil Extraordinair!


« Reply #34 on: March 12, 2010, 03:34:58 PM »

Code:
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);

function loopF(event:TimerEvent):void{
var time:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();

var hour:Number = time.getHours();
var minute:Number = time.getMinutes();
var second:Number = time.getSeconds();

date_txt.text = month + "/" + day + "/" + year;
time_txt.text = hour + ":" + minute + ":" + second;

if (day < 10){
date_txt.text = month + "/" + "0" + day + "/" + year;
} else {
date_txt.text = month + "/" + day + "/" + year;
}
if (hour > 12){
time_txt.text = hour-12 + ":"  + minute + ":" + second;
} else {
time_txt.text = hour + ":"  + minute + ":" + second;
}
if (minute < 10){
time_txt.text = hour + ":" + "0" + minute + ":" + second;
} else {
time_txt.text = hour + ":" + minute + ":" + second;
}
if (second < 10){
time_txt.text = hour + ":"  + minute + ":" + "0" + second;
} else {
time_txt.text = hour + ":" + minute + ":" + second;
}

}
Can someone help me find out why this isn't working?
<a href="http://www.truploader.com/uploads/282516Clock.swf" target="_blank">http://www.truploader.com/uploads/282516Clock.swf</a>

I tried else if  for the rest of it and that only causes it to run an error message.
« Last Edit: March 12, 2010, 03:49:34 PM by TheGrayK » Logged

The novelty of my own mortality has yet to be torn,
While the vulgarity of my existence has made its welcome worn.
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1418


/* No comment */


WWW
« Reply #35 on: March 12, 2010, 10:53:47 PM »

It looks like it's working to me... Undecided

Edit: these two lines are unnecessary though:
Code:
date_txt.text = month + "/" + day + "/" + year;
time_txt.text = hour + ":" + minute + ":" + second;

Also you have a very strange indentation style. Tongue

Edit again: Actually I think I know what problem you're talking about. If we change it a bit...

Code:
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);

function loopF(event:TimerEvent):void{
var time:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();

var hour:Number = time.getHours();
var minute:Number = time.getMinutes();
var second:Number = time.getSeconds();

var minuteStr:String = minute;
var secondStr:String = second;

if (day < 10){
date_txt.text = month + "/" + "0" + day + "/" + year;
} else {
date_txt.text = month + "/" + day + "/" + year;
}
if (hour > 12){
hour = hour-12;
}
if (minute < 10){
minuteStr = "0" + minute;
}
if (second < 10){
secondStr = "0" + second;
}

time_txt.text = hour + ":" + minuteStr + ":" + secondStr;
}
« Last Edit: March 12, 2010, 11:07:05 PM by Jaehl » Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
Vector
Resident Actionscript Guru
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 3803


~ Programmer | National Laser Tag Player | Bent ~


WWW
« Reply #36 on: March 13, 2010, 12:32:12 AM »

Also you have a very strange indentation style. Tongue

It's interesting, actually, because you'll find for some languages it's actually a more accurate representation of how the if-else blocks are handled (at least, internally).

Code:
if (day < 10){
date_txt.text = month + "/" + "0" + day + "/" + year;
} else {
date_txt.text = month + "/" + day + "/" + year;
}

You can also do stuff like this
Code:
   // Shorthand if statements can reduce the need for multiple if blocks
    // They take the form of
    // a= ( b ? c : d );
    // which is the same as
    // if( b ) {
    //     a = c;
    // } else {
    //     a = d;
    //  }
    date_txt.text = month + "/" ( day < 10 ? "0" + day : day ) + "/" + year;
    
    // Modulus: gives you the remainder. eg 4 % 5 equals 1, because 4 divided by 5 has 1 remainder
    // Gotta be careful, because 12 % 12 = 0 (ie,12 divided by 12 has 0 remainder)
    hour %= 12; (Modulus will give values 0 to 11, where 0 is the same as 12am/pm)
    hour = ( hour == 0 ? 12 : hour ); // Make hour 12 if hour is 0
    
    // Again, inline if statements can reduce additional lines. This is used in a slightly
    // different way to the last one - the intention is probably more visible here, but at the cost of
    // slightly more overhead because you're always building a string.
    minuteStr = ( minute < 10 ? "0" : "") + minute;

And if you wanted to get really tricky, you could possibly even do this with the hours one (warning: untested!)

Code:
   // Take the modulus of hour, assign it to hour, and make hour 12 if it's zero.
    // Note the hour %= 12 is an ASSIGNMENT operator, that is, it is setting the value
    // of hour! This can be a big gotcha if you're not careful...!
    // It's the same sort of thing as if( a = b ) instead of if( a == b )

    hour = ( (hour %= 12) == 0 ? 12 : hour );
« Last Edit: March 13, 2010, 12:47:29 AM by Vector » Logged

~Vector
Jaehl
Mobal Gloderator
Global Moderator
Veteran
***
Offline Offline

Gender: Male
Posts: 1418


/* No comment */


WWW
« Reply #37 on: March 13, 2010, 01:08:47 AM »

I was never really a big fan of the ternary operator, though I'm not exactly sure why. Undecided
Logged


<a href="http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf" target="_blank">http://i17.photobucket.com/albums/b90/Jaehll/Actionscript_Banner.swf</a><a href="http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf" target="_blank">http://img.photobucket.com/albums/v661/Vector88/motm.swf?vTitle=oct%2Fnov%2007.swf</a>
Sarus translator:
<a href="http://www.jaehl.com/files/progress.swf" target="_blank">http://www.jaehl.com/files/progress.swf</a>
TheGrayK
That Awesome Guy You Know
Senior Member
****
Offline Offline

Gender: Male
Posts: 907

Daredevil Extraordinair!


« Reply #38 on: March 13, 2010, 02:42:15 AM »

...these two lines are unnecessary though:
Code:
date_txt.text = month + "/" + day + "/" + year;
time_txt.text = hour + ":" + minute + ":" + second;

Yeah I originally took them out after I got the if statements done but when it started messing up I put them back in just in case.

Also you have a very strange indentation style. Tongue
ha ha I guess it just helps my brain organize it a little better lol

Actually I think I know what problem you're talking about. If we change it a bit...
Hmm that didnt seem to work for me. but I truly appreciate the help!

You can also do stuff like this
Code:
    // Shorthand if statements can reduce the need for multiple if blocks
    // They take the form of
    // a= ( b ? c : d );
    // which is the same as
    // if( b ) {
    //     a = c;
    // } else {
    //     a = d;
    //  }
    date_txt.text = month + "/" ( day < 10 ? "0" + day : day ) + "/" + year;
   
    // Modulus: gives you the remainder. eg 4 % 5 equals 1, because 4 divided by 5 has 1 remainder
    // Gotta be careful, because 12 % 12 = 0 (ie,12 divided by 12 has 0 remainder)
    hour %= 12; (Modulus will give values 0 to 11, where 0 is the same as 12am/pm)
    hour = ( hour == 0 ? 12 : hour ); // Make hour 12 if hour is 0
   
    // Again, inline if statements can reduce additional lines. This is used in a slightly
    // different way to the last one - the intention is probably more visible here, but at the cost of
    // slightly more overhead because you're always building a string.
    minuteStr = ( minute < 10 ? "0" : "") + minute;

this is what I ended up doing aside from changing 0 to 12 because I think that is a little too advanced for me right now.
thank you for your help and here is the finished product and code.

Oh and P.S.
The shortened if statement really cleaned it up.
to see that it's working it needs to be some time afternoon
<a href="http://www.truploader.com/uploads/128946Clock.swf" target="_blank">http://www.truploader.com/uploads/128946Clock.swf</a>
and the code
Code:
var looper:Timer = new Timer(100);
looper.start();
looper.addEventListener(TimerEvent.TIMER, loopF);

function loopF(event:TimerEvent):void{
var time:Date = new Date();
var month:Number = time.getMonth()+1;
var day:Number = time.getDate();
var year:Number = time.getFullYear();

var hour:Number = time.getHours();
var minute:Number = time.getMinutes();
var second:Number = time.getSeconds();

date_txt.text = month + "/" + (day < 10 ? "0" + day : day) + "/" + year;
time_txt.text = (hour > 12 ? hour-12 : hour) + ":" + (minute < 10 ?  "0" + minute : minute)+ ":" + (second < 10 ? "0" + second : second);

}

« Last Edit: March 13, 2010, 02:48:53 AM by TheGrayK » Logged

The novelty of my own mortality has yet to be torn,
While the vulgarity of my existence has made its welcome worn.
Vector
Resident Actionscript Guru
Assistant Admin
Heroic
****
Offline Offline

Gender: Male
Posts: 3803


~ Programmer | National Laser Tag Player | Bent ~


WWW
« Reply #39 on: March 16, 2010, 10:10:06 PM »

I was never really a big fan of the ternary operator, though I'm not exactly sure why. Undecided

If you're not chaining them and they're not too complex, I don't see the problem in using them, but it seems to be a love it or hate it thing for a lot of programmers. Personally, I love it. Tongue
Logged

~Vector
Brackenwood
   

 Logged
Pages: 1 2 [3]   Go Up
Print
Jump to:  

Theme by Pieter, based on Black Rain by Crip Powered by SMF 1.1.16 | SMF © 2011, Simple Machines XHTML | CSS

Page created in 0.237 seconds with 24 queries.