Skip to main content
Participating Frequently
January 21, 2013
Question

Newbie needs help calling functions.

  • January 21, 2013
  • 1 reply
  • 1628 views

Hello.  First, so everyone knows what I'm trying to accomplish, I have a Flash website I am building usingover 300 .png's  (named home0264.png, home0265.png, etc.) in my flash folder inside a folder called "images" that were output from a 3D animation program to create my animation.  The animation is a metal wheel that rotates towards the user based on the link they are currently hovering over (seen here-  teamsuperior.org).

The problem is that using all the frames I need to create the animation has resulted in a huge file that makes the functionatlity of the website non existent for a typical user.  I asked about this a while back and a good hearted soul provided me with the following code to perform those functions as opposed to using frames to do it:

var tl:MovieClip=this;

var imageNum:int=0260;

var imageTotal:int=0524;

loadF();

function loadF():void{

tl["loader_"+imageNum]=new Loader();

tl["loader_"+imageNum].contentLoaderInfo.addEventListener(Event.COMPLETE,loadcompleteF);

tl["loader_"+imageNum].load(new URLRequest("images/home"+imageNum+".png"));

}

function loadcompleteF(e:Event):void{

if(imageNum<imageTotal){

imageNum++;

loadF();

} else {

// loading of the images is complete.  you can now display any sequence without delays.  ie, start your app

startF();

}

}

/* Mouse Over Event

Mousing over the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is moused over.

*/

    function displayF([0260,0261,0263,0264,0265,0266,0267,0268]):void{

    tl.imageA=imageA;   

    tl.currentIndex=0;   

    tl.addChild(tl["loader_"+imageA[0]]);   

    tl.addEventListener(Event.ENTER_FRAME,enterframeF);   

    }

   

    

   

    function enterframeF(e:Event):void{   

    tl.removeChild(tl["loader_"+tl.imageA[tl.currentIndex]]);   

    tl.currentIndex++;   

    if(tl.currentIndex<tl.imageA.length){   

    tl.addChild(tl["loader_"+tl.imageA[tl.currentIndex]]);   

    } else {   

    tl.removeEventListener(Event.ENTER_FRAME,enterframeF);   

    }

   

    }

SO HERE"S MY QUESTION (FINALLY):

First, I am fairly new to action script so I use snippets a lot but these larger functions I have no idea where to put them or how to call them using an event (i.e. do I use the full code for the function on the event or just the function name?  Anyone willing to type out an example I would apprecaite so I see the format and syntax for this)

Second I get these errors when trying to run the animation:

expecting identifier before left bracket

expecting rightparen before leftbrace

This occurs for the top line of code that reads:

function displayF([0260,0261,0263,0264,0265,0266,0267,0268]):void{

    tl.imageA=imageA;   

    tl.currentIndex=0;   

    tl.addChild(tl["loader_"+imageA[0]]);   

    tl.addEventListener(Event.ENTER_FRAME,enterframeF);   

    }

Will someone who knows syntax help me figure out what the issue is?  I think that's all I need.  Thanks very much in advance.

This topic has been closed for replies.

1 reply

Inspiring
January 21, 2013

if you want to pass an Array into a function,

it would be sth. like this:

function displayF(_arr:Array):void{

    tl.imageA=imageA;   

    tl.currentIndex=0;   

    tl.addChild(tl["loader_"+imageA[0]]);   

    tl.addEventListener(Event.ENTER_FRAME,enterframeF);   

    }


displayF(new Array(0260,0261,0263,0264,0265,0266,0267,0268));

but since you are doing nothing inside the function with the argument, I don`t really see what you want to achieve

Participating Frequently
January 21, 2013

Well I recieved the code from someone else, so really maybe he expected me to fill in certain values (which I tried to do which is probably why the function isn't typed correctly).  So the

displayF(new Array(0260,0261,0263,0264,0265,0266,0267,0268)); do I put this inside the event or just typ this in the script as you have it then assign it to an event some other way?