Write this code in few lines?

Reffer the code below. I've got 120 names (apple, lemon, lime...) and 10 movieclip objects (wood_mc, metal_mc, dust_mc). I need a way to make the code short.
//SET 1
colorchange = new Color(wood_mc);{
if (myclip== "APPLE"){
colorchange.setRGB(0x94372C);
if (myclip== "LEMON"){
colorchange.setRGB(0xF4B000);
//repeated 118 times more...
//SET 2
colorchange = new Color(metal_mc);{
if (myclip== "APPLE"){
colorchange.setRGB(0x94372C);
if (myclip== "LEMON"){
colorchange.setRGB(0xF4B000);
//repeated 118 times more...
this entire code goes in the same frame.

var fruitcolor:Object = new Object();
fruitcolor.APPLE = 0x94372C;
fruitcolor.LEMON = 0xF4B000;
//...et al...
function setFruitColor(who:MovieClip, colorID:String){
     if(fruitcolor[colorID]==null){
          trace(colorID +" is not a valid ColorID!");
          return false;
     var c = new Color(who);
     c.setRGB(fruitcolor[colorID]);
     return true;
I am not sure what you mean by SET #, but maybe the above might help.
More or less to use, you need to populate fruitcolor with each of your color names and the color numbers.
Then to use the function, you simply do the following:
setFruitColor(wood_mc, "APPLE");
//or check if a color was successfully added:
if ( setFruitColor(wood_mc, "BROWN") ){
     trace("Color was added Successfully!!!!");
}else{
     trace("Woopsie Doodles, you seem to have encountered an error!");
Hope this helps!
-GK

Similar Messages

  • How to write this code ?

    I need to write 3 classes that each one can get to the other with the same instance of the class , so how do i write this code ?
    thanks a lot

    try out singleton pattern with all the three classes. following link may help...
    http://www.javareference.com/jrexamples/viewexample.jsp?id=25

  • Who can help me? write this code?

    Write java code print prime number like this
    Sample Screen Print:
    Initial matrix with N = 37
    2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37
    Intermediate results (after 1st iteration)
    2 3 5 7 9
    11 13 15 17 19
    21 23 25 27 29
    31 33 35 37
    Intermediate results (after 2nd iteration)
    2 3 5 7
    11 13 17 19
    23 25 29
    31 35 37
    Intermediate results (after 7th iteration)
    2 3 5 7
    11 13 17 19
    23 29
    31 37
    Final results
    2 3 5 7 11 13 17 19 23 29
    31 37
    How to write this code ?
    Please Help me!
    Thank you so muchhh ?????

    Looks like The Sieve of Eratosthenes.
    A google search for that should help you with some logic.
    Wikipedia has a really nice animation of how it works.
    Post back when you have some source code that you need help with.
    Thanks k???? lullzz???

  • Yahoo email account not open after i write this code in c#

    Hi guys i make send email by this code 
    but after one week the yahoo account  not open why 
    the yahoo account not open is [email protected]
    and this is my code 
    string smtpAddress = "smtp.mail.yahoo.com";int portNumber = 587;
    bool enableSSL = true;
    string emailFrom = "[email protected]";
    string password = "passw#rd";
    string emailTo = "[email protected]";
    string subject = "Working Finish today" + label6.Text;
    string body = "Summary for Date" + "" + label6.Text + "" +
    "Quantity Required" + "" + "(" + label17.Text + ")" + "/" +
    "Quantity Shipped""/" + "(" + label18.Text + ")" + "/" +
    "Quantity Remaining" + "/" + "(" + label19.Text + ")";
    using (MailMessage mail = new MailMessage())
    mail.From = new MailAddress(emailFrom);
    mail.To.Add(emailTo);
    mail.Subject = subject;
    mail.Body = body;
    mail.IsBodyHtml = true;
    mail.Attachments.Add(new Attachment("I:\\gridview" + DateTime.Today.ToString("dd-MM-yyyy") + ".csv"));
    System.Net.Mail.SmtpClient smtp = new SmtpClient(smtpAddress, portNumber);
    smtp.Credentials = new NetworkCredential(emailFrom, password);
    smtp.EnableSsl = enableSSL;
    smtp.Send(mail);
    What is wrong in this code 
    I create account by yahoo two times 
    and after this open may be 6 days and after this not open
    and cannot open your yahoo account after this i try from another computer but not open
    i check caps lock and every thing and language and i write in files before i open 
    but not accept to open
    Why 

    @ahmedsalah2012
    >>IF problem is limitation How i now the limitation finish or still exist
    I've just do a quick search. Please refer  to
    http://group-mail.com/sending-email/email-sending-limits-for-isp-web-hosting-and-free-email-providers/
    For more information about the options available to send more email than allowed by your current outgoing SMTP mail server, read
    Email Send Limits and Options.
    Based on your scenario, your Email is Yahoo, please also consider to post in Yahoo official website for more specific response.
    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience
    to you. 
    Microsoft does not control these sites and has not tested any software or information found on these sites;Therefore, Microsoft
    cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you
    completely understand the risk before retrieving any software from the Internet.
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I need help please if you can aid me in my quest to write this code

    I am trying really hard to accomplish this and my head hurts from trying mulitple ideas on the right code.A lottery requires that you select six different numbers from the integers 1 to 49. Write a Java program that will do this for you and generate five sets of six numbers as a result.
    Details:
    For generating random numbers you can use the random() static method of class Math. It returns a double so you will need to cast it as an integer. If you set the range to 49, you can generate a random number between 1 and 49 through:
    number = (int) ( range * Math.random() ) + 1;
    Note that you need 5 sets of numbers and in each set you have should have six different numbers. There should not be duplicate numbers within each set. Of course the same number can occur in multiple sets, but within the same set of 6 numbers it should only occur once, if at all.
    Here is an example of a valid set of numbers: 5, 41, 3, 9, 22, 30
    Here is an example of an invalid set of numbers: 15, 8, 19, 33, 8, 21
    It is invalid because the number 8 appears twice.
    This is the dilema the code I have so far (I know it is not much) is import java.util.Scanner;
    import java.util.Random;
    public class Lottery
    public static void main(String[] args)
              int[] numbers = new int[6];
    number = (int) (range 49 Math.random() ) + 1;
    am I on the right track totally wrong or???? Please help me and god bless

    Tinkerbell... wrote:
    Navy_Coder wrote:
    Tinkerbell... wrote:
    Navy_Coder wrote:
    Yeahhhhh, don't do that...Why not?because you butchered an otherwise simple process by the whole generic list with 50 numbers and sorting mess.
    java.util.Random. <-- learn how to use it.Well, please explain how you would better do it using java.util.Random then?
    Random r = new Random();
    int[] vals = new int[6];
    for(int i = 0; i < vals.length; i++ )
        vals[i] = (r.nextInt(49) + 1);

  • How could I write this code?

    I am trying to create a shared object that will host a chat
    room environment. I will have many of these rooms and I know what I
    want to do, just not how to write it in actionscript or if it is
    even possible. the underlined portion is what i just don't know how
    to code (
    (room + roomNumber + _so) ) as it should throught usage
    equate to something like
    room1_so,
    room2_so,
    room3_so, and so on. any help would be greatly appreciated.
    thanks in advance.
    function doJoin(roomNumber) {
    (room + roomNumber + _so) = SharedObject.getRemote(
    (room + roomNumber + _so) ,_root.clientroom_nc.uri,true);
    if(
    (room + roomNumber + _so) ).data.seat1 = occupied) {
    do this;
    }

    its actually connecting to flash media server remote shared
    object as opposed to the local shared object. The code in question
    was actually taken nearly word for word from the macromedia sample
    file so I know that that portion is correct.
    If I replace the shared object name from
    tl["room"+roomNumber+"_so"].connect(_root.clientroom_nc);
    and change it to
    room1_so.connect(_root.clientroom_nc);
    everything works fine and the connection is succesful,
    however since I hope to have many many rooms that is just not a
    feasible way to write it. I have racked my brain trying to think of
    an alternative way of writing it but have come up with nothing. I
    am well versed in Basic, PHP, and some C, but this damn
    actionscript stuff is throwing me for a loop since it is incredibly
    different in a lot of ways.

  • Who can help me write this Java code show the prime number ???? PLEASEEEEEE

    Write java code print prime number like this
    Sample Screen Print:
    Initial matrix with N = 37
    2 3 4 5 6 7 8 9 10
    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29 30
    31 32 33 34 35 36 37
    Intermediate results (after 1st iteration)
    2 3 5 7 9
    11 13 15 17 19
    21 23 25 27 29
    31 33 35 37
    Intermediate results (after 2nd iteration)
    2 3 5 7
    11 13 17 19
    23 25 29
    31 35 37
    Intermediate results (after 7th iteration)
    2 3 5 7
    11 13 17 19
    23 29
    31 37
    Final results
    2 3 5 7 11 13 17 19 23 29
    31 37
    How to write this code ?
    Please Help me!
    Thank you so muchhh ?????

    h2. {color:#ff0000}Multiplepost{color}
    Replies here: http://forum.java.sun.com/thread.jspa?threadID=5241012&tstart=0
    There is a useful answer the original thread. Answer it, or ignore it as you like, but don't create multiple threads.

  • What is the error in this code

    hi everone
    I write this code in push button
         declare
              x varchar2(222);
         begin
              x:=get_application_property(:system.mode);
              message(x);
              end;
    to know the system mode
    but the resullt was exeception ora-06502

    simple write
    x := :system.mode;
    or
    message(:system.mode);
    message(:system.mode);Best way to resolve the issue is always check Forms online help first

  • What is the problem in this code

    hi
    im tring to ftech mutliple reords to tabuler form text item
    i write this code but its only fetch values for first record in the text item and do not fetch to other records in the same text item
    Declare
    cursor c is
    select distinct group_a from sc_mast; <here i select all values
    in my database that they are 63 values>
    begin
    for r in c loop
    next_record;
    :visib_groups.group_a:=r.group_a;<it assign vakues only for first record>
    end loop;
    end;

    This?
    Go_block('>your_block<')
    first_record;
    begin
    for r in c loop
    :visib_groups.group_a:=r.group_a;<it assign vakues only for first record>
    next_record;
    end loop;Ros

  • How to write C# code in HTML code?

    Hi,
    I want that write C# code in script tag in html document. I write this code:
    <script>
    function AddNewLinkfn()
    var LinkName = prompt("Please enter Link Name:", "");
    var LinAddress = prompt("Please enter Link Address:", "");
    if (LinkName != "" && LinAddress != "" && LinkName != null && LinAddress != null) {
    <% string esmelink=%> LinkName <% ,adreselink= %> LinkAddress<%;%>
    </script>
    but this has error.
    I Thanks anyOne that guide me. :)
    Good luck!

    Hi Bahare,  
    The <script> tag is used to define a client-side script, such as a JavaScript.
    The <script> element either contains scripting statements or it points to an external script file through the src attribute.Common
    uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
    You should write C# code inside asp.net (C#)(.cs).page. For more infomation,Please check
    http://msdn.microsoft.com/en-us/library/vstudio/k33801s3(v=vs.100).aspx
    In addition,
    This forum is to discuss problems of C# development.
    You'll need to post it in
    ASP.NET forum for more efficient responses, where you can contact ASP.NET experts.
    Best Regards,
    Kristin

  • How do I write this as a loop?

    How do I write this code to function as follows.
    When btn1 is clicked, SenderLoad should be "clay" AND when btn2 is clicked, SenderLoad should be "iron", etc...
    var mgB:Array = [btn1, btn2, btn3, btn4];
    var mgBW:Array = ["clay", "iron", "cotton", "leather"];
    var SenderLoad:LoadVars = new LoadVars();
    var ReceLoad:LoadVars = new LoadVars();
    var mgNum:Number=0;
    for (i=0; i<mgBW.length ; i++){
    mgBW[i].onRelease = function () {
    mgNum++
    SenderLoad.word = mgB[mgNum];
    SenderLoad.sendAndLoad("http://www.web.com/my.php",ReceLoad,"POST");
    ReceLoad.onData = function(src) {
    var messageA:Array = src.split(",,,");
    ldrB2.html=true;
    for(var i:Number=0; i<messageA.length; i++){
               var a:Array=messageA[i].split(",,");
       ldrB1.htmlText +=a[0];
       ldrB2.htmlText +=a[1];

    if you want different words in different colors you can use:
    ldrB1.html=true;
    ldrB1.text = formatF("REJECT",0xff0000,ldrB1)
    ldrB1.text = formatF("ACCEPT",0x000000,ldrB1);
    ldrB1.text = "formatF("BANNED",0xc0c0c0,ldrB1);
    function formatF(s:String, col:Number, tf:TextField):Void {
    if(tf.text.indexOf(s)==-1){
    return;
        tfor.color = col;
        var startindex:Number = 0;
        while (startindex>-1 && startindex<tf.text.length-1) {
            var bindex:Number = tf.text.indexOf(s, startindex);
            var eindex:Number = bindex+s.length;
            tf.setTextFormat(bindex,eindex,tfor);
            startindex = eindex;
    var tfor:TextFormat = new TextFormat();

  • Userexit to write PAI code

    Hi All
    I had to write code at PAI event ON VALUE REQUEST for a custom field which I had added to VL02N transaction on the header --> processing tab.Can anybody give the userexit which is suitable to write this code.The program name is SAPMV50A.
    Regards
    Praneeth

    Hi
    Go to SE80 transaction and then choose PROGRAM from dropdown and then give your Program name(SAPMV50A) then it will display the tree , there you can see all PAI Modules present in the program. Depending on the requirement choose the Module and write your code.
    Reward  points if helpful.
    Regards
    Swathi

  • Add pause in this code....help!!!!

    hi everybody!!!
    i'm writing code for up and down speed of song....
    for play of song i write this code:
    public function playMC(evt:MouseEvent):void
                target= new ByteArray();
                var url:URLRequest = new URLRequest("C://song.mp3");
                mp3Start = new Sound();
                mp3Start.addEventListener(Event.COMPLETE, complete);
                mp3Start.load(url);
                position = 0.0;
                rate = 1.0;
                sound = new Sound();
                sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sampleData);
    public function complete(event:Event):void
                channel = sound.play();
    this code is good for only play and stop song....i want add pause song....how to do??
    help me please!!!!

    hi!!!
    now i have another small problem...
    i want add one timer ans progressBar...
    for add time i write this:
    public function getCurrentSong(evt:TimerEvent):void
                                  currentSong.text = convertTimer(sound.position);
    but don't go same time!!!!
    and how to use the sliderBar or progressBar in this player???
    help me please!!!!

  • Do u know how to write a few line of codes to create folder?

    hi all, I just need a few line of codes to create a folder in my directory. Can someone just write a few lines of codes to create a folder?Thanks!
    This is my unzip codes and I need to put these few lines of codes in the "/* */" part. If I didn't create the folder (using codes)then it would not be unzipped.
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    public class Unzip {
      public static final void copyInputStream(InputStream in, OutputStream out)
      throws IOException
        byte[] buffer = new byte[1024];
        int len;
        while((len = in.read(buffer)) >= 0)
          out.write(buffer, 0, len);
        in.close();
        out.close();
      public static final void main(String[] args) {
        Enumeration entries;
        ZipFile zipFile;
        try {
          zipFile = new ZipFile("C:\\Temp\\FolderZiper.zip");
          entries = zipFile.entries();
          while(entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry)entries.nextElement();
    /*need to have the few lines of codes here*/
            if(entry.isDirectory()) {
              // Assume directories are stored parents first then children.
              System.err.println("Extracting directory: " + entry.getName());
              // This is not robust, just for demonstration purposes.
              (new File(entry.getName())).mkdir();
              continue;
            System.err.println("Extracting file: " + entry.getName());
            copyInputStream(zipFile.getInputStream(entry),
               new BufferedOutputStream(new FileOutputStream(new File("c:\\temp\\unzipping\\"+entry.getName()))));
          zipFile.close();
        } catch (IOException ioe) {
          System.err.println("Unhandled exception:");
          ioe.printStackTrace();
          return;
    }

    Given a file, you can create its parent directory like this:
    File outFile = new File("c:\\temp\\unzipping\\"+entry.getName())
    File parentDir = outFile.getParentFile();
    if (!parentDir.exists()){
      parentDir.makeDirs();
    }Not too hard is it?

  • Hi can anyone see anything glaringly wrong in this code its only a few line

    class test
    public static void main(String []args)
    public void display()
         int limit=5;
         int total=0;
         for (int i = 0; i<limit; i++)
              System.out.println(i*i+i);
              total+=i;
         System.out.println(total);

    see after running this code
    public class test
         public static void display()
         int limit=5;
         int total=0;
         for (int i = 0; i<limit; i++)
              System.out.println(i*i+i);
              total+=i;
                   System.out.println(total);
                        public static void main(String []args)
                                  display();
    I get this output
    0
    2
    6
    12
    20
    10
    but when i work it out in my mind i get this
    2
    12
    and then i stop because i wonder why i didnt get the 0 and why i missed the 6
    can anyone work out what im doing wrong
    thanks

Maybe you are looking for