Quantcast
Channel: Adobe Community : All Content - Edge Animate
Viewing all articles
Browse latest Browse all 9897

Recycle code and dynamic data

$
0
0

resdesign helped me create a function earlier today which I just tidied up a bit below…. my code was sloppy.

It got me thinking, what if you wanted to recycle the code.

 

1) Is it logical to assume that this would make the file load time even faster.

2) It would make the project / object / method scalable from project to project.

 

So for example, lets say the following controls a drop menu

 

var A=1;

var mymenu = sym.getSymbol("themenu")

mymenu.$("thebttn").click(function(){

  if(A==0){

  mymenu.playReverse('closeit');

  A=1;

  }else{

  mymenu.play('openit');

  A=0;

  }

});

 

 

What if you wanted now to say you had 2 iterations (or any other number for that matter) of the same menu object but it was going to load in unique data.  How would or even could you automate that?

Or would you have to write out the code block twice like….

 

var A=1;

var mymenu = sym.getSymbol("themenu")

mymenu.$("thebttn").click(function(){

  if(A==0){

  mymenu.playReverse('closeit');

  A=1;

  }else{

  mymenu.play('openit');

  A=0;

  }

});

 

//second menu

var B=1;

var mymenu2 = sym.getSymbol("themenu2")

mymenu2.$("thebttn").click(function(){

  if(B==0){

  mymenu2.playReverse('closeit');

  B=1;

  }else{

  mymenu2.play('openit');

  B=0;

  }

});

 

 

mymenu.stop("openit");

mymenu2.stop("openit");

 

I've added the base file set up that I used to create this at this link for anyone to view / modify https://www.dropbox.com/sh/farjoa32vnv0fyh/AACOpnerkKNdSSH1cqW_Q3bPa?dl=0

I'll pull them down in about a week though. just keeping things tidy.


Viewing all articles
Browse latest Browse all 9897

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>