Crap...
My bad, I sent a code sample that didn't have the function calls I was getting from the XML.
Your sample is exactly what I was looking for.
I never included the functions that the array contains because I figured that was assumed.
They are just two functions right now that look like this...

        private function playNextSection(e:MouseEvent):void{
                        //
                        var val:Number = stepArray[stepCount].pv;
                        var functionCall:String = stepArray[stepCount]["fnct"];
                        this[functionCall](val);
                        textwindow.captionTxt.text = stepArray[stepCount].txt;
                        stepCount++
                }
                
                private function testFunction(num:Number):void{
                        trace("you called testFunction,  num --> "+num);
                }

                private function testFunctionOne(num:Number):void{
                        trace("you called testFunctionOne, num --> "+num);
                }

Everything is working the way I wanted.

Thanks,

-Gerry


On Sep 6, 2008, at 12:31 PM, jonathan howe wrote:

Mike asks an important question, but assuming for the moment the function is
in the same class as playNextSection():

What you're retrieving from the XML is a String. So the line
stepArray[stepCount]["fnct"](val);
isn't going to call a function. It's going to try to treat a string as a
function... and the main way to do that is via [ ] notation.
I think it's most readable to separate it into two steps:

var functionName:String = stepArray[stepCount]["fnct"];
this[functionName](val); // assuming it's in this class. You may also have
to cast this[functionName] this as a function; can't test right now

-jonathan



On Sat, Sep 6, 2008 at 12:09 PM, Mike Chambers <[EMAIL PROTECTED]> wrote:

Where is the actual function?

You cant store a function in XML, on the name. You can then use that name
to construct a call to the function. Where is the function?

mike chambers

[EMAIL PROTECTED]

mike chambers

[EMAIL PROTECTED]

On Sep 6, 2008, at 7:40 AM, Gerry wrote:

Mike,
Neither of these options are working.

-Gerry
Here's what my XML looks like:

     <steps>
             <step>
                     <text>NEW TEXT.</text>
                     <funct>testFunction</funct>
                     <pausev>1.5</pausev>
             </step>
             <step>
                     <text>NEXT TEXT to display .</text>
                     <funct>testFunctionOne</funct>
                     <pausev>2.5</pausev>
             </step>
     </steps>

I have a button that is named mentorNext with this event listener..
mentorNxt.addEventListener(MouseEvent.CLICK,playNextSection);

the function "playNextSection" looks like this...

private function playNextSection(e:MouseEvent):void{
                     //
                     var val:Number = stepArray[stepCount].pv;
                     //stepArray[stepCount].fnct(val);
                     stepArray[stepCount]["fnct"](val);
                     textwindow.captionTxt.text =
stepArray[stepCount].txt;
                     stepCount++
             }


If I remove the line for the stepArray function the
textwindow.captionText line works.
The data is there the array is populated properly but I can't get the
function to act like a function.
I get this error message:

TypeError: Error #1006: value is not a function.
     at MainIntro/::playNextSection()


Thanks,

-Gerry





On Sep 6, 2008, at 12:47 AM, Mike Chambers wrote:

if fnct is a function:

stepArray[0].fnct();

if it is a string:

stepArray[0]["fnct"]();

The 0 is the index from the array you want to retrieve.

mike chambers

[EMAIL PROTECTED]

On Sep 5, 2008, at 8:30 PM, Gerry wrote:

I have an array built from and XML file that I want to step through
and one of the nodes will have
a function to call. I thought I did this in AS2 before but can't find
my code.
I'm stuffing my array with the function string cast as an object
but I
can't seem to find any hints on
how I should be calling that function.
My array is built like this...
[code]
//this works fine
   for each (var step:XML in xmlData..step) {
           var step_text:String = step.text;
           var stepFunc:String = step.funct;
           var stepPause:Number = step.pausev;

stepArray.push({txt:step_text,fnct:stepFunc,pv:stepPause});
   }

[/code]
I want to call the stepArray.fnct but can't seem to get it to work
nor
can I find an example of how I should go about this.
Any help or link would be greatly appreciated.


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




--
-jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to