如何使用flash按钮触发Ajax?

时间:2011-06-07 04:36:05

标签: ajax actionscript-3

我正在开发一些有2个链接触发某些Ajax的东西。但是我需要将链接转换为Flash按钮(AS3)。我以前从未使用过Ajax,我也不知道如何做到这一点。

修改

Ajax:

<script>
    $(document).ready(function() {

          $('a.catlink').unbind('click').click(function(e)
          {

                  e.preventDefault();

                  var link = $(this);
                  var inputs = [];                      

                  var cat_type = $(this).attr('href').replace('#', '');

                  link.attr('disabled', 'disabled');

                  inputs.push('cat_type=' + escape(cat_type));

                  $.ajax(
                   {
                     type: "POST",
                     cache: false,
                     dataType: "html",
                     url: window.location.href,
                     data: inputs.join('&'),
                     success: function(html)
                       {
                          var json = $.parseJSON(html);

                          if (json['status'] == 1)
                          {
                              $('div.listing').html(json['html']);
                          }
                          link.removeAttr('disabled');                            
                       }
                   });
          });
      });
</script>

HTML

    <h1 class="section-head">Products  
      // **The 2 links*** //
      <a class="catlink" href="#cinema">cinema</a> <a class="catlink" href="#smart">smart</a></h1>
    <div class="listing">
      <ul class="listing">
          {foreach from=$products item="product_info"}
          <li class="clearfix">
              <div class="inner-left">
                  <a href="{if $product_info.title_url}{$product_info.title_url}{else}{$product_info.url}{/if}"><img height="68" width="90" src="{$product_info.image}" /></a>
                  <h2 class="normal mt-5"><a href="{$product_info.url}">{if $product_info.price != '0'}${$product_info.price}{else}Click for price &raquo;{/if}</a></h2>
              </div>
              <div class="inner-right">
                  <h3 class="mb-0"><a href="{if $product_info.title_url}{$product_info.title_url}{else}{$product_info.url}{/if}">{$product_info.productName}</a></h3>
                  <p class="small mb-5"><span class="quiet">{$product_info.category}</span></p>
                  <p class="mb-15">{$product_info.description}</p>
                  <a class="button getprice" href="{$product_info.url}">Buy Now</a>
                  <br><br>
              </div>
          </li>
          {/foreach}
      </ul>
    </div>

1 个答案:

答案 0 :(得分:0)

如果您要使用AS3,则可以使用ExternalInterface.call()在页面上调用JavaScript函数。但是,如果您使用AS3,则可能不需要使用Ajax,因为您可以使用URLLoader类来执行相同的操作(调用PHP脚本并解码结果)。

如果你更准确地描述你想要达到的目标,那么我将提供一些示例代码并澄清一点。