This content has been marked as final.
Show 3 replies
-
1. Re: Populating scene with Action Script
Newsgroup_User Jul 11, 2007 4:35 AM (in response to Nejkodebejko1)Sure, no problem actually. I'd use two pieces of code. The first would be a
class, extending MovieClip, and attached to your button clip in the library.
Then a little for loop on the main timeline to attach the buttons to the
stage and you're all set.
For the class:
class com.yourdomain.Sample extends MovieClip
{
var myID:Number;
function Sample(){}
function set id(newID:Number):Void
{
myID = newID;
this.onRelease = function(){
trace(this.myID);
}
}
}
Of course, you'll need to change the com.yourdomain to your own class path.
Then just set your clip in the library to export for ActionScript and set
the class to: com.yourdomain.Sample
On the main timeline then, write a little createGrid function like so:
function buildGrid(tot, sx, sy, pc, cs, rs){
var startX = sx;
var currX = startX;
var startY = sy;
var perCol = pc;
var colSpace = cs;
var rowSpace = rs;
//use tot + 1 because we're going from 1 not 0 in the for loop below
var total = tot + 1;
for(var i=1; i < total; i++){
var clip = this.attachMovie("btn", "btn" + i, i+10, {_x:currX,
_y:startY});
clip.id = i;
currX += colSpace;
if(i % perCol == 0){
startY += rowSpace;
currX = startX;
}
}
}
And call it:
buildGrid(100, 20, 20, 10, 12, 12);
This will make a grid of 100 instances of the clip named 'btn' (the one with
your class attached), starting at 20,20 with 10 per row and 12 pixels
between centers... When you click any of them they will trace their
appropriate index 1 - 100
HTH
--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/
-
2. Re: Populating scene with Action Script
Nejkodebejko1 Jul 11, 2007 11:21 AM (in response to Newsgroup_User)Hello Dave,
Thank you very much. You're a life saver.
I got it working, but im still not sure how i did it :) .
Now i have a additional request. How could i connect every populatet button with XML => PHP => MYSQL. Dont worry explaining about php or mysql. I would just like to know how could a button read from XML, and depending on the setting in its xml row to be colured ex. red for not available and blue for still available.
So the big question is checking the xml for the state of the button, available or unavailable, and then reacting to that state in flash movie.
Hope you can help,
thanks again,
sincerely,
Nejc Palir -
3. Re: Populating scene with Action Script
Newsgroup_User Jul 12, 2007 5:48 AM (in response to Newsgroup_User)>>how could a button read from XML, and depending on the setting in its xml
>>row to be colured ex. red for not available and blue for still available.
Assuming you can read and parse the XML, you could read your button states
into an array. Then, when you build the grid check the array for the state
of the current button.
Your state array might just be a bunch of integers:
stateArray = [0,1,1,0,1,.......];
In the loop, right after where you set the clip's id, you could check the
state:
if(stateArray[i-1]){
//stateArray is 1 for this clip - set it to red or something
}
I put i-1 since the for loop in my example counts from 1 and array indexes
begin at 0.
HTH
--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/