View Full Version : Create Buttons. Please, could someone help me? Thank You.
shapper
February 8th, 2010, 10:45 AM
Hello,
I have a Flash Movie with 11 movies:
R1, R2, ..., R10 (Each one is a square); and MARK
On Flash vars I receive a variable as follows:
IDsLIST="1,4,5".
I need, based IDsLIST values, to do some changes.
So for each movie R which ID is included in IDsLIST do the following:
1. Change the square color;
2. Place a copy of MARK over the square and center it;
3. Make the Square a button with:
a) URL: http://www.mydomain.com/region/id
b) When the mouse is over the square change the color of the square.
Could someone, please, help me with this?
Thank You,
Miguel
mathew.er
February 8th, 2010, 01:01 PM
So let's break it down into simple tasks...
1. you need to get the list of ID's:
var idList : Array = stage.loaderInfo.parameters['IDsLIST'].split ( ',' );
2. iterate trough the ID's and do that magicy stuff
var l : int = idList.length;
for ( var i : uint = 0; i < l; i++ ) {
// get a refference to R(N)
var r : MovieClip = getChildByName ( 'R' + idList[i] );
// save the ID for later use
r.id = idList[i];
// next steps...
}
3. To place "MARK" there, you'll need to do a few things...
Delete it from the stage. Go to it's properties in the library, set "export for ActionScript" and set "Class" to "Mark". Then, in code, you can create a copy of it with
new Mark ();To center it over R, use
// create new mark
var mark : Mark = new Mark ();
// center it
mark.x = r.x + ( r.width - mark.width ) / 2;
mark.y = r.y + ( r.height - mark.height ) / 2;
// display it
addChild ( mark );
4. To make the square a clickable button
r.addEventListener ( MouseEvent.CLICK, r_clickHandler );
// and somewhere outside of the for loop define a that handler function
function r_clickHandler ( e : MouseEvent ) : void
{
var url : String = 'http://www.mydomain.com/region/' + (e.currentTarget as MovieClip).id;
navigateToURL ( new URLRequest ( url ) );
}
I doesn't include the color changes as we have a raid in about 1 minute, but you could do that with some filters or by having another child in your Rs that you would switch to visible/invisible.
So the code so far is:
var idList : Array = stage.loaderInfo.parameters['IDsLIST'].split ( ',' );
var l : int = idList.length;
for ( var i : uint = 0; i < l; i++ ) {
// get a refference to R(N)
var r : MovieClip = getChildByName ( 'R' + idList[i] );
// save the ID for later use
r.id = idList[i];
// next steps...
// create new mark
var mark : Mark = new Mark ();
// center it
mark.x = r.x + ( r.width - mark.width ) / 2;
mark.y = r.y + ( r.height - mark.height ) / 2;
// display it
addChild ( mark );
r.addEventListener ( MouseEvent.CLICK, r_clickHandler );
}
// and somewhere outside of the for loop define a that handler function
function r_clickHandler ( e : MouseEvent ) : void
{
var url : String = 'http://www.mydomain.com/region/' + (e.currentTarget as MovieClip).id;
navigateToURL ( new URLRequest ( url ) );
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.