AS 2.0 Datagrids and SWF files
by Char Cole
on
Jul 28, 2008 at 9:15:11 pm
Currently I have just successfully learned how to add a datagrid and populate it from a database by way of PHP. What I am trying to do now is find out if there is a way to load a small swf (animated graphic) into one of the columns to display that someone is online. I have tried just putting the img src in but of course it only brings back the URL. Any help would be great!
Here is the code I have so far:
AS 2.0
stop();
// define global styles and easing equations for the problems_cb ComboBox
_global.style.setStyle("themeColor", "red");
_global.style.setStyle("fontFamily", "Verdana");
_global.style.setStyle("fontSize", 10);
_global.style.setStyle("openEasing", mx.transitions.easing.Bounce.easeOut);
//Getting the stuff for the datagrid
var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();
for (var i:Number=0; i < varNum; i++) {
dgMobster.addItem({Online:varOnline, Mobster:varName, Button:dButton, Crew:dCrew, Networth:varNet});
}
};
dgMobster.setSize(470, 300);
// Make DataGrid non-editable.
dgMobster.editable = false;
// set formatting of online column
// auto-sort will work fine for this column
dgMobster.getColumnAt(0).width = 45;
dgMobster.getColumnAt(0).headerText = "Online";
// set formatting of mobster column
dgMobster.getColumnAt(1).width = 125;
// trap header click event to sort case-insensitive on this field
//dgMobster.getColumnAt(2).sortOnHeaderRelease = false;
// this property will keep track of whether sort is ascending or descending
dgMobster.getColumnAt(1).sortedUp = false;
dgMobster.getColumnAt(1).headerText = "Mobster";
// set formatting of button column
dgMobster.getColumnAt(2).width = 75;
// trap header click event to sort numerically
dgMobster.getColumnAt(2).sortOnHeaderRelease = false;
//dgMobster.getColumnAt(3).sortedUp = false;
dgMobster.getColumnAt(2).headerText = "Button Men";
// set formatting of crew column
dgMobster.getColumnAt(3).width = 75;
// trap header click event to sort numerically
//dgMobster.getColumnAt(4).sortOnHeaderRelease = false;
//dgMobster.getColumnAt(4).sortedUp = false;
dgMobster.getColumnAt(3).headerText = "Crew";
// set formatting of net column
dgMobster.getColumnAt(4).width = 75;
// trap header click event to sort numerically
//dgMobster.getColumnAt(5).sortOnHeaderRelease = false;
//dgMobster.getColumnAt(5).sortedUp = false;
dgMobster.getColumnAt(4).headerText = "Networth";
}
Char
"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher
Re: AS 2.0 Datagrids and SWF files by Pieter Helsen on Jul 28, 2008 at 11:37:22 pm
Heya Char,
I would attach a movieclip over the datagrid like so...
var gridHeight:Number = 300;
// calculate how high each row will be.
var rowHeight:Number = gridHeight / varNum;
for (var i:Number=0; i < varNum; i++) {
dgMobster.addItem({Online:varOnline, Mobster:varName,
Button:dButton, Crew:dCrew, Networth:varNet});
var online_mc:MovieClip = this.attachMovie("onlineStatus_mc", "online" + i + "_mc",
this.getNextHighestDepth(), {_y:gridHeight*i});
online_mc.gotoAndPlay("offline");
}
// The onlineStatus_mc would of course just be a small movieclip
// with a graphic for each state ("offline", "online" frame labels)
// Use an if-statement, for example, to decide to which frame label to go.
Heh, kinda hard to explain :) Hope this helped you out.
You can only add data to a datagrid.
Kind regards,
Pieter
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
Re: AS 2.0 Datagrids and SWF files by Char Cole on Jul 29, 2008 at 12:35:03 am
Ok so I tried that and its still passing the 1 or 0 for online or offline. The question I have then is obviously I need to pull the data from the database to tell it if the user online or off, how do I tell the mc variable which one to play?
I guess I am way not understanding this :( I tried looking up attaching movie to a datagrid but all I got were a bunch of claases I could take for four days? LOL And yes I created the mc. Essentially what I am trying to do is put a .gif on the people that are online to "attract" your attention to them LOL.
var gridHeight:Number = 300;
// calculate how high each row will be.
var rowHeight:Number = gridHeight / varNum;
for (var i:Number=0; i < varNum; i++) {
dgMobster.addItem({Online:varOnline, Mobster:varName,
Button:dButton, Crew:dCrew, Networth:varNet});
var online_mc:MovieClip = this.attachMovie("onlineStatus_mc", "online" + i + "_mc",
this.getNextHighestDepth(), {_y:gridHeight*i});
online_mc.gotoAndPlay("offline");
}
};
"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher
Re: AS 2.0 Datagrids and SWF files by Char Cole on Jul 29, 2008 at 1:44:35 am
I realized I copied the wrong code into here without my if statement, but to be honest I think I am so frustrated right now that Im just going to put asterics in for now and move onto another portion of it.
Ill have to re-visit this later. Im just not understanding it LOL but thanks for the help!
Char
"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
Re: AS 2.0 Datagrids and SWF files by Pieter Helsen on Jul 29, 2008 at 2:15:20 pm
Lol, yeah, that goes in your actionscript.
Kind regards,
Pieter
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
var gridHeight:Number = 300;
// calculate how high each row will be.
var rowHeight:Number = gridHeight / varNum;
for (var i:Number=0; i < varNum; i++) {
dgMobster.addItem({Online:varOnline, Mobster:varName,
Button:dButton, Crew:dCrew, Networth:varNet});
var online_mc:MovieClip = this.attachMovie("onlineStatus_mc", "Online" + i + "_mc",
this.getNextHighestDepth(), {_y:gridHeight*i});
if (this.varOnline = "1"){
online_mc.gotoAndPlay("online");
} else {
online_mc.gotoAndPlay("offline");
}
}
};
Luckily I still have some of my hair and got some sleep ;)
Char
"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher
Re: AS 2.0 Datagrids and SWF files by Pieter Helsen on Jul 29, 2008 at 10:06:09 pm
if (this.varOnline == "1")
Clearly not enough ;)
Kind regards,
Pieter
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
Re: AS 2.0 Datagrids and SWF files by Char Cole on Jul 29, 2008 at 10:35:06 pm
Damn LOL do you do this stuff for a living? ;)
Ok I went back and looked at the code and saw what I had done (which you had just pointed out). I left old code in that I was testing when I was trying to make my own if loop. I copied yours directly into it and still its passing the "on", "off" variable.
So as I know that you cannot make a call to something in flash before its available, there are a couple of questions I have so that perhaps I understand it better.
1. After fixing the loop, does that need to go after the call that assigns the data array into the datagrid? Or should it go before?
2. Where it says dgMobster.addItem({Online:varOnline, Mobster:varName, Button:dButton, Crew:dCrew, Networth:varNet}); should I be leaving the varOnline in there? Or should that be changed to something else.
3. I put another ( in front of .attachMovie so I could see what each "element" in the () were for. The first one being the idName. Now if my understanding of this is correct (and I know this question is probably stupid) that is the name of the actually movie clip correct?
Just want to make sure I totally set this up right. Which I believe I did.
Thanks again for your help! I cannot believe how much I have learned in the last 2-3 weeks :)
Char
"I think... I think it's in my basement... Let me go upstairs and check!" - M.C.Escher
That should just put a space there. The movieclips should be positioned over that anyhow.
3) The first parameter is the Identifier (not an instance name). Basically what attachMovie does, is grab a movieclip from the library and attach it to the stage. To know which MC it needs to grab, you need to give it a linkage name. Right-click on the movieclip in the library and choose 'Properties...'. Check Export for Actionscript.
Kind regards,
Pieter
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.