All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
  Print view

Arena rating calculator in Flex
Author Message
PostPosted: Sat Sep 20, 2008 9:47 pm 
Offline
New Coder

Joined: Wed Sep 10, 2008 6:57 am
Posts: 14
Location: The Netherlands
So yeah, I got a bit bored today and tried to make an arena rating calculator in Flex3.

Latest build (click)

Build from below (click)

Source code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>
   <![CDATA[
      private var rating:Number;
      private var points:Number;
      
      // Calculate the points you will get for a certain rating
      private function CalculatePoints(percentage:Number, ratingInput:Number):Number
      {
         // if the rating is below 1500 use this formula
         if (ratingInput < 1500)
         {
            points = Math.round((ratingInput * .22 + 14) * percentage);
            return points;
         }
         // if the rating is over 1500 use this forumula
         else
         {
            points = Math.round((1511.26 /(1 + (1639.28 * Math.pow(2.71828 , (-0.00412 * ratingInput))))) * percentage);
            return points;
         }
      }
      
      // calculate the rating needed for each bracket to gain certain points
      private function CalculateRating(percentage:Number, pointsInput:Number):Number
      {
         // formula to go from points to rating
         rating = Math.round(Math.ceil(Math.log((1511.26 / (1639.28 * pointsInput / percentage)) - ( 1 / 1639.28)) / ( -0.00412 )));
         
         // if the rating is lower or equal to 1500 use the other forumla
         // if not return the formula used first
         if (rating <= 1500) {
            rating = Math.round(((pointsInput / percentage)-14)/0.22);
            return rating;
         }
         else
         {
            return rating;
         }

      }
      
      // Calculate the ratings using the CalculateRating function
      // then display the ratings in the given objects
      public function ShowRatings(pointsInput:Number):void
      {
         ratingReqText.text = "Rating required for " + String(pointsInput) + " points:";
         ratingOutput1.text = String(CalculateRating(.76, pointsInput))
         ratingOutput2.text = String(CalculateRating(.88, pointsInput))
         ratingOutput3.text = String(CalculateRating(1, pointsInput))
      }
      
      // Calculate the points using the CalculatePoints function
      // then display the points in the given objects
      public function ShowPoints(ratingInput:Number):void
      {
         pointsGivenText.text = "Arena points for a " + String(ratingInput) + " rated team:";
         pointsOutput1.text = String(CalculatePoints(.76, ratingInput))
         pointsOutput2.text = String(CalculatePoints(.88, ratingInput))
         pointsOutput3.text = String(CalculatePoints(1, ratingInput))
      }
   ]]>
</mx:Script>

   <mx:Button x="222" y="14" label="calculate points" click="ShowPoints(Number(ratingInput.text))" width="125"/>
   <mx:Button x="222" y="42" label="calculate rating" click="ShowRatings(Number(pointsInput.text))" width="125"/>
   <mx:TextInput x="158" y="14" id="ratingInput" restrict="0-9" maxChars="4" width="55"/>
   <mx:TextInput x="158" y="42" id="pointsInput" restrict="0-9" maxChars="3" width="55"/>
   <mx:Label x="24" y="106" text="2v2 Bracket:" width="80"/>
   <mx:Label x="24" y="132" text="3v3 Bracket:" width="80"/>
   <mx:Label x="24" y="158" text="5v5 Bracket:" width="80"/>
   <mx:Label x="24" y="222" text="2v2 Bracket: " width="80"/>
   <mx:Label x="24" y="248" text="3v3 Bracket: " width="80"/>
   <mx:Label x="24" y="274" text="5v5 Bracket:" width="80"/>
   <mx:Label x="24" y="44" text="Desired arena points:"/>
   <mx:Label x="24" y="16" text="Arena team rating:"/>
   <mx:Label x="24" y="80" text="Rating required:" width="323" id="ratingReqText"/>
   <mx:Label x="24" y="196" text="Arena points for rating:" width="323" id="pointsGivenText"/>
   <mx:Label x="103" y="106" id="ratingOutput1" width="244"/>
   <mx:Label x="103" y="132" id="ratingOutput2" width="244"/>
   <mx:Label x="103" y="158" id="ratingOutput3" width="244"/>
   <mx:Label x="103" y="222" id="pointsOutput1" width="244"/>
   <mx:Label x="103" y="248" id="pointsOutput2" width="244"/>
   <mx:Label x="103" y="274" id="pointsOutput3" width="244"/>
   
</mx:Application>


So the problem is that I want to seperate the Actionscript from the MXML file it is in now, because it will be good practice for later work.
I know how to build the seperate AS class, only now i'm stuck with the 2 show functions (showPoints and showRating) because they cant acces the labels anymore now.
So could anyone give me a handy solution for this? (my goal is to get rid of the most actionscript in the MXML file for as far as its possible)


Last edited by Bamboocha on Sun Sep 21, 2008 9:53 am, edited 5 times in total.

Top
 Profile E-mail  
 

Re: Arena rating calculator in Flex
PostPosted: Sun Sep 21, 2008 12:52 am 
Offline
Site Admin

Joined: Tue Sep 09, 2008 5:29 pm
Posts: 52
This is the first time I've seen anything done in flex and tbh it looks rather pointless you could have done the entire thing in JS in about 4 lines :(
I'm sure it has more use when used with flash since then its actually performing operations.

Apart from that though I'm sorry can't help you know nothing about this stuff :)

_________________
CDOSYS & CDONTS auto detecting mail function: Mail Function
500.100.asp debug page: Debug Script


Top
 Profile E-mail  
 

Re: Arena rating calculator in Flex
PostPosted: Sun Sep 21, 2008 9:16 am 
Offline
New Coder

Joined: Wed Sep 10, 2008 6:57 am
Posts: 14
Location: The Netherlands
after alot of fucking around I figured it out and it works the way I want it now.

Shall I make a tutorial out of this? it covers pretty much the basic things you want to know about how to work with Flex3.


Top
 Profile E-mail  
 

Re: Arena rating calculator in Flex
PostPosted: Sun Sep 21, 2008 5:13 pm 
Offline
Site Admin

Joined: Tue Sep 09, 2008 5:29 pm
Posts: 52
sure if you fancy writing a tutorial

_________________
CDOSYS & CDONTS auto detecting mail function: Mail Function
500.100.asp debug page: Debug Script


Top
 Profile E-mail  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron