Groups | Blog | Home
all groups > flash actionscript > march 2007 >

flash actionscript : asfunction not working


David Stiller
3/5/2007 8:22:56 PM
aniebel,

[quoted text, click to view]

It shouldn't. Let's see what you've got in your code.

[quoted text, click to view]

So far, that looks fine. The above assumes that a string is being
passed into the fMailTo() function as a parameter, and that the parameter is
an email address.

[quoted text, click to view]

When this hyperlink is clicked, asfunction, will invoke the fMailTo()
function and pass it the parameter anyname@anydomain.com -- at least, it
should. I would add a trace() statement inside the fMailTo() function to
make sure a) the function is being triggered at all and b) is receiving the
email address as expected. (The @ symbol might, for example, need to be
escaped, though I don't think that would be necessary.)

[quoted text, click to view]

So far, so good.

[quoted text, click to view]

Is sList is an array? If so, you would need to pull a particular
element from that array, right? Something like ...

phoneList_txt.htmlText = sList[0];

Could that be it?


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."

aniebel
3/5/2007 11:44:41 PM
Does the fact that I'm parsing this XML have anything to do with the fact that
the mailto: function does not work?

This is the function in Flash:
function fMailTo(email)
{
getURL("mailto:" + email);
}

This is an attribute from my XML:
email="<a
href='asfunction:fMailTo,anyname@anydomain.com&apos;>anyname@anydomain.com</a>"

which, after being parsed and when traced appears like this in the output
window:
<a href='asfunction:fMailTo,anyname@anydomain.com'>anyname@anydomain.com</a>

going into a dynamic text field with the following properties applied:
phoneList_txt.html = true;
phoneList_txt.htmlText = sList;

sList is where all names, email addresses, etc. are
David Stiller
3/6/2007 11:41:08 AM
aniebel,

[quoted text, click to view]

That was my hunch.

[quoted text, click to view]

I'm thinking asfunction simply can't "see" the fMailTo() function from
where it's positioned.

The first goal is to make sure fMailTo() gets triggered. From there,
you'll be able to trace that parameter and see right away if the incoming
string is formatted as you expect. If the text field that contains
asfunction is nested inside a movie clip or some other hierarchy, try one of
these approaches:

a) precede the function name with a path ...
<a href='path.to.asfunction:fMailTo, // etc.

b) write a liaison function in the scope of that text field that can do the
pathing for you ...
<a href='asfunction:fLocalMailTo, // etc.

function fLocalMailTo(param:String):Void {
path.to.fMailTo(param);
}


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."

David Stiller
3/6/2007 2:39:41 PM
aniebel,

[quoted text, click to view]

Yeah, if your code is also in _level0 (that is, the main timeline), then
that really shouldn't be a problem. This is starting to get interesting.
;)

[quoted text, click to view]

They sure should be -- that scope being the main timeline.

Have you be able to duplicate this issue in another FLA? That would be
my next step. Create a new FLA, slap down a quick dynamic text field, and
feed it a hard-coded anchor tag with an asfunction href. Right below the
ActionScript that accomplishes that, write the function referenced by
asfunction and trace that function to see if it fires.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."

aniebel
3/6/2007 3:48:36 PM
Thanks for responding, David. I traced the fMailTo function and it's not
showing as being called. How can I troubleshoot "why" it's not being called?

sList is a string from aList which is an array. I've taken attributes from an
XML file and put them in order with tabs to display a phone list.

I've acheived this from formatting the text as follows:

function fInit() {
var aList:Array = new Array();
for (i=0; i<aListings.length; i++) {
aList.push(aFNames[i], "SPACE", aLNames[i], aExts[i], aCells[i], aEmails[i],
aTitles[i], "RETURN");

}
for (j=0; j<aListings2.length; j++) {
aList2.push(aFNames2[j], "SPACE", aLNames2[j], aExts2[j], aCells2[j],
aEmails2[j], aTitles2[j], "RETURN");
}
var format:TextFormat = new TextFormat();
format.tabStops = [40, 150, 210, 250, 320, 550];
format.leading = 8;
var sList:String;
sList = aList.toString();
sList = sList.split(",SPACE,").join(" ");
sList = sList.split(",RETURN,").join("\n");
sList = sList.split(",RETURN").join("");
sList = sList.split(",").join("\t ");
phoneList_txt.html = true;
phoneList_txt.htmlText = sList;
phoneList_txt.setTextFormat(format);
searchPanel_mc.result_txt.setTextFormat(format);
}
Lujunq
3/6/2007 5:40:17 PM
Hi, is this happening everytime you try to use asfunction or just at this case?
I always come up with problems while using asfunction when I embed flash
content on my html page using the dreamweaver solution to avoid that acitvex
problem (the javascript include of the flash content).
aniebel
3/6/2007 7:11:00 PM
Hmmm... I don't think I understand. If I debug and show variables, the
textfield shows as "Target="_level0.phoneList_txt""

The function is also on the main timeline. In this case, are they not both in
the same scope?

aniebel
3/6/2007 8:07:38 PM
Here's a link to the files used in this issue:
aniebel
3/6/2007 8:21:21 PM
OOPS! sorry, that was stuffit... not zip. This one's zipped.

aniebel
3/6/2007 9:32:36 PM
Ok, thanks to David's help, the answer was found by removing the "asfunction"
altogether and using a simple "mailto:" in the XML attribute instead. Not sure
but maybe it had something to do with how I was splitting and joining elements
in the string.
AddThis Social Bookmark Button