问问题
686 次
2 回答
0
嗨,您可以使用LocationChangeEvent
JS->AS3 进行相反的“对话”,这样您就可以准备链接,从而提供使用 JSON 传递的大量参数。以下是我的程序的摘录,它在StageWebView
(HTMLLoader
具有相同的事件) 中呈现长列表并返回单击事件以及有关它的一些详细信息:
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, onWebLocationUpdate, false, 0, true);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, onWebLocationUpdate, false, 0, true);
protected function onWebLocationUpdate(e:LocationChangeEvent):void
{
trace(e);
//JS->AS
if (e.location.indexOf("message://") != -1)
{
var jsonString:String = e.location.substr("message://".length);
var myObject:Object = JSON.parse( jsonString );
for (var name:String in myObject)
{
trace(name + ":" + myObject[name]);
}
e.preventDefault();
}
}
JS
jQuery(document).ready(function() {
// do something here
//alert("Ready");
$(".rowItem").click(function(e)
{
$(this).toggleClass("rowItemSelected");
$(this).bridgeSend($(this).attr("id"),$(this).hasClass("rowItemSelected"));
});
});
(function( $ ){
$.fn.bridgeSend = function(id, selected)
{
var method = "select";
var json = "{\"item\":{\"selected\":"+selected+",\"name\":\""+id+"\"},\"method\":\""+method+"\"}";
window.location = "message://"+json;
};
})( jQuery );
HTML
<div class="rowItem" id="entry2">
<div class="top">
<div class="icon"><img src="css/clock.png" /></div>
<div class="date"><h3>Fri, 04-09-2010</h3></div>
</div><!-- end of the top -->
<div class="desc">
<p><strong>Title</strong></p>
<p>The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
</div><!-- end of the desc -->
<div class="times">
<div class="col1">09:00</div>
<div class="col2">09:30</div>
<div class="col3">0.50</div>
</div>
</div><!-- end of the rowItem -->
于 2013-03-20T08:19:14.377 回答
0
于 2015-06-18T17:38:32.830 回答