-
Flash / Php / Sql / As
Hi all,
after some digging, research and late nights I feel comfortable with getting flash to write to and extract data from a SQL database (via PHP).
Now on to phase two: I am creating a fully dynamic site, contents as well as the framework the content will reside in.
I am going to have plenty of questions as they come up and hope that I can get some help from the Board.
Step 1 - I have the basics of a dynamic menu (http://prototype.emarket2.com/Craig_...namicmenu.html)
So far the flash file loads the php, the php queries the db, and when the information is received the menu appears, this is in a loop. Great the menu items are all there with external url access, but how do I get the menu item to kick off an internal ActionScript rather than an external link. My SQL DB has two fields title and url.
Any help out there ??? On request I can post or mail the src code.
Kindest
Craig
-
Hi,
it should NOT loop... - use either a frame loop or an onclipevent(data) handler to create the menu when loadvariables has completed once.
You are assigning the urls to the url member of your menu items - just generalize this concept:
if the menu item has a frame member, make something go to the specific frame, if it has funcname and funcarg members, call the specified actionscript function, else use the url member to load a new page
Musicman
-
Originally posted by Musicman
Hi,
Hi Musicman,
Thank you for responding.
It should NOT loop... - use either a frame loop or an onclipevent(data) handler to create the menu when loadvariables has completed once.
I have used a frameloop because I found that it takes a little while to process the PHP and retreive the data.
I tried on an onclipevent but if the data did not load quick enough it would not show up in flash.
This is my PHP -
while($row = mssql_fetch_object($result))
{
// build label string
$labelStr .= $row->label . "|";
// build link string
$linkStr .= $row->link . "|";
}
// print output as form-encoded data
echo "items=" . urlencode($labelStr) . "&urls=" .
urlencode($linkStr);
}
basically checking that a record exists,etc, etc. if there is a record bring in the two fields - label and link seperated by a pipe.
You are assigning the urls to the url member of your menu items - just generalize this concept:
if the menu item has a frame member, make something go to the specific frame, if it has funcname and funcarg members, call the specified actionscript function, else use the url member to load a new page
This is the AS
// split variables into array
items = items.split("|");
urls = urls.split("|");
// get position of template movie clip
yPos = getProperty("itemInstance", _y);
// iterate over array elements
for (i=0; i<(items.length-1); i++)
{
// clone movie clip and name it
duplicateMovieClip ("itemInstance", "itemInstance"+i, i);
// set position
setProperty ("itemInstance"+i, _y, yPos+i*25);
// set variables
set ("itemInstance"+i+".label", items[i]);
set ("itemInstance"+i+".url", urls[i]);
}
Splits out the variables with a pipe, finds the position of the button parses the data clones the button drops the data into the cloned button.
How and at which piont should it be formatted to trigger internal functions ??
Looking forward to any help you can offer.
Kindest
Musicman
-
Hi,
say you were adding the funcname and funcarg bits: you need some way to express that in the database, in the variables, etc.
This approach is just one way: if the url looks like http:, it is treated as an url, else it should be funcname,arg [the arg so you could call one particular func with different args]
There is no change to the php / mysql this way and to splitting the vars, but populating the menu would become:
Code:
for (i=0; i<(items.length-1); i++)
{
// clone movie clip and name it
duplicateMovieClip ("itemInstance", "itemInstance"+i, i);
// set position
setProperty ("itemInstance"+i, _y, yPos+i*25);
// set variables
set ("itemInstance"+i+".label", items[i]);
if(urls[i].indexOf("http") == 0)
set ("itemInstance"+i+".url", urls[i]);
else
{ f = urls[i].split(",");
set ("itemInstance"+i+".func", f[0]);
set ("itemInstance"+i+".fnarg", f[1]);
}
}
and your button action should be
Code:
on(release)
{
if(typeof(this.func) != 'undefined')
_root[this.func](this.fnarg);
else
getURL(this.url, "....");
}
Musicman
-
Allrightey,
after some frustration (my ignorance mostly)I have got it semi working just the bit getting internal functions working, in my db I am using the example:
gotoAndPlay (10);
Should this work, I notice you are using a comma for your splitter in the second part of your script is this neccessary for ActionScript ??
Kindest
-
Hi,
the database entry should read
gotoAndPlay,10
with that setup.
Also, for going to frames, you should probably add a function like
showframe(x)
{ _root.gotoAndPlay(x);
}
and then use showframe,10 as the database entry
Musicman
-
Thanks
Thanks Musicman,
I'll give that a bash as soon as I get in tommorrow.
Where about are you based (continent) Just curious ?
Kindest
-
Thanks
Yea Man,
It works.
Thanks
-
More Questions
Hi Musicman,
If I want to bring in a variable from my db to populate a fiels in flash can I do this as a function and argument ??
I am struggling a bit with it.
Kindest
-
Hi,
if there are not too many text boxes, a function settext1 that sets textbox 1 to its argument should do
Musicman
-
Thanks for that will get on it right now.
Quick question, do you think the way I am going about setting this site up lots of processing in the DB and PHP is the way to go ??
I just had an "alleged" top end developer telling me for 5 mins that this will cause problems and break later on.
Any Suggestions ??
Thanks in advance
-
oops
Sorry cannot get it to work
db entry is:
set text1,helloo
input field in flash is:
text1
Still nothing happening I have tried variotions on set property, variables and about 30 othe guesses, no go.
kindest
-
Hi,
text in db should be:
settext1,blah
this will call a function settext1 (which you have to provide)
function settext1(t)
{ _root.text1 = t;
}
replace the _root with path to actual textbox variable if required
Musicman
-
Hi,
text in db should be:
settext1,blah
this will call a function settext1 (which you have to provide)
function settext1(t)
{ _root.text1 = t;
}
replace the _root with path to actual textbox variable if required
Musicman
-
-
Last question for today
Yea man its working.
Thank you
Ok now to more advanced this creates one menu item and appropriate sub menu's, how can I add a second and third set ?
I have tried various options, creating a second table and trying using the same procedure to get the php to load the data into a second renamed retargeted button "services"
When creating the second set of data I think it conflicts with the loaded first set.
Is there a way I can target just the relevant data from 'one' table to create a different submenu for each of the 2 menu items.
Then how can I get the menu to roll down and back up to dissapear from each menu heading when in and not in use ?? If you can give me a a broad idea I can try eek it out tommorrow.
I have a fully working version using flat text, if only I could get my db to behave like loaded txt i would be on the button
This is a link to the so far vers. ignore bits and pieces wreckage from experiments.
http://prototype.emarket2.com/Craig_...namicmenu.html
Any help once again appreciated and I wont harrass you till at least Friday
Kindest
-
Maybe just a general overview
Maybe just a general overview,
if not any directions
Once its finished I'll post thea tutorial and source files on flashkit
Kindest
-
New Approach
Hi Musicman
After a little insite from my last post Flash/As/PHP/SQL I am trying a different approach.
I am now getting Flash to talk directly to SQL is there any reason not to do this ??
I now have my variables comming into flash and populating a pseudo static menu.
I bring all my data in target my menu and voila the title and link are operational, only thing as with my previous attempt I need to get the menu to operate internally, not just call external url's.
AS:- data is my Movie Clip
************************************************** ********************
stop ();
with(data){
for (i=1; i<=numMenus; i++) {
numLinks = (eval("menu"+i+"Links"))*1;
set ("_root.menu"+i+".numLinks", numLinks);
for (j=1; j<=numLinks; j++) {
theTitle = eval("menu"+i+"Link"+j+"Title");
set ("_root.menu"+i+".link"+j+".theTitle", theTitle);
theLink = eval("menu"+i+"Link"+j+"Url");
set ("_root.menu"+i+".link"+j+".theLink", theLink);
}
}
}
************************************************** ********************
All I need it to do is for each menu item to go to a different frame number.
As always any help appreciated.
Kindest
-
Hi,
I think you can use the same method as last time. So if theLink (your intermediate variable that takes the url) looks like a real url, assign it to the MC's url, otherwise process otherwise.
You could even extend the concept here: if the entire variable is a number, assign it to the MC's "frame" property and change the button script such that a value for frame causes the button to make the root goto that frame
Musicman
-
Thanks
Thank you
As soon as I am in I'll give it a bash and send you a link to see the completed version.
Kindest
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|