in Education by
I want to check whether the color = a certain color then appropriately react. This is done in flash AS3. the code I've got is if(cal_mc.color == 0x0000FF) { p1score = p1score + 25; (cal_mc being the object) It executes without any errors but doesn't work. Can anyone tell me what I'm doing wrong with the if statement? Preferably keeping the code as simple as possible. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As far as I understand, you are using a simple MovieClip object in your code (cal_mc is of type MovieClip). Short answer: There is no property "color" on MovieClip, so your first condition fails. Long answer: MovieClips by definition are dynamic objects, so that means they can have properties defined while your code is running: var custom:MovieClip = new MovieClip(); custom.potato = "I am a potato!"; // creates a new property "potato" and assigns it the value of "I am a potato". trace(custom.potato); // outputs "I am a potato"; There is no property "color" on MovieClip, so your condition statement is false in the theoretical state, but practically flash doesn't throw any errors, since MovieClips can have properties assigned at runtime, so flash cannot know, If you haven't defined "color" somewhere. The are few solutions: Either to create a custom class extending the MovieClip which would contain color property and some methods to draw the graphics you want and logic to assign the correct value to the color property when the drawing is complete. If your MovieClip is a simple shape, which I assume it is — render the MovieClip to Bitmap object, and then sample the first pixel (since all of the pixels of simple shapes are of the same color) from the Bitmaps bitmapData. Here's the code for the latter: (this code may require tweaking, it's an outline) function sampleColorFromDisplayObject(display:DisplayObject):uint { var bd:BitmapData = new BitmapData(display.width, display.height, false, 0xFF0000); bd.draw(display, new Matrix()); var color:uint = bd.getPixel(0, 0); bd.dispose(); return color; } Keep in mind, that due to various possible shapes and sizes, this code may require tweaking and may not work as intended with some shapes. I've made the code working with as big amount of shapes as possible by making the bitmapData big in dimensions and sampling the first pixel to account for certain types of circles and shapes defined in the flash IDE.

Related questions

0 votes
    Alright, currently I have my SWF hitting a php file that will go and find all the files I specify ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 18, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Have you found such a tool and used it successfully? JavaScript questions and answers, JavaScript questions pdf ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Have you found such a tool and used it successfully? JavaScript questions and answers, JavaScript questions pdf ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    We are building sentiment analysis application and we converted our tweets dataframe to an array. We created another array ... .txt").getLines.toArray var happyCount=0 for (e...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    We are building sentiment analysis application and we converted our tweets dataframe to an array. We created another array ... .txt").getLines.toArray var happyCount=0 for (e...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I just want to know whether a blob exists in a particular container or not. Simple question right! I'll download ... it doesn't exist. Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    var currentClassName = $(this).parent('td').next('td').find('input:text').attr('class'); if ( ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    Let's say that I declare a C struct called foo, which has an int field called bar and a char * ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    In my password reset function the user can put in whatever he/she wants. It does not even needs ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
...