2 Replies Latest reply on Jul 26, 2014 10:30 AM by HHJsyndrome

    Creating and deleting symbols dynamically

    HHJsyndrome Level 1

      I need help with getting this particular function implemented.

       

      I have 2 buttons with codes which I've added

       

      //Create button

      $.getJSON("content.JSON")

        .success(

        function(data){

        console.log("incoming data: ", data);

       

       

        //console.log("this is current value of var s", template);

       

       

        if (s == null)

        {

        $.each(data, function(index, item){

        //var s = sym.createChildSymbol( "template", "content");

        s = sym.createChildSymbol( "template", "content" );

        // Creating the variable that save my new instance of mySymbol

        sym.setVariable("itemContainer"+i, s);

        console.log("item container name", s);

       

        s.$("title").html( item.item );

        s.$("description").html( item.description );

        s.play(index * -500);

        i++;

        //console.log("'dressbtn' inside was CLICKED");

        });

        }

        else

        {

        }

        });


      //Delete button

      for(var p = 1; p <= i; p++)

      {

      s = sym.getVariable("itemContainer"+p);

      s.deleteSymbol();

      }

       

      i = 1;

       

      So the two buttons one will get the items from Json and display them, and the other will clear the symbols created.

      But I've only managed to clear the symbols on stage only once, and after that I'm getting Javascript error in event handler! Event Type = element

       

      The reason is because I'm trying to make an app that can get information off a json file from a webserver and able to update and display the lastest information in the app. So I've to be able to allow the user to press a button to refresh the page.

       

      Can anyone shine some light on this?

       

      Dropbox - test.zip

        • 1. Re: Creating and deleting symbols dynamically
          joel_pau Level 5

          Hi,

           

          Your issues (or troubles) come from your json file. Your json file is not well formed.

          Here is a correct one:

          {"shoes":[

          {"item":"red shoe","description":"prada red shoe"},

          {"item":"black shoe","description":"Black canvas shoe"},

          {"item":"tilith shoe","description":"tilith ballet shoe"},

          {"item":"gold shoe","description":"gold ballet shoe"},

          {"item":"ganma shoe","description":"ganma canvas shoe"}

          ]}

           

          Then your buttons code:


          1) mybtn.click:

          //get json information and display

          $.getJSON("content.JSON")

            .success( function(data){

            console.log("incoming data: ", data);

            $.each( data.shoes, function(index, item){

            var s = sym.createChildSymbol( "template", "content");

            s.$("title").html( item.item );

            s.$("description").html( item.description );

            s.play(index * -500);

            } );//each

             } );//success


          2) btn_2.click:

          //deleting shoes (symbols)

          var symbols = sym.getChildSymbols();

          $.each(symbols, function(index, item){

            console.log("symbols on stage: ",item.getSymbolTypeName());

            if (item.getSymbolTypeName() == "template") item.deleteSymbol();

          });

           

          Download link: test-2 - copie.zip - Box

          • 2. Re: Creating and deleting symbols dynamically
            HHJsyndrome Level 1

            thanks alot joel, I've learnt something new =)