void as_global_clearinterval(const fn_call& fn) { if (fn.nargs > 0) { fn.get_root()->remove_listener(fn.arg(0).to_object()); } }
void sprite_start_drag(const fn_call& fn) { sprite_instance* sprite = sprite_getptr(fn); character::drag_state ds; ds.SetCharacter(sprite); if (fn.nargs > 0) { // arguments have been given to startDrag ds.SetLockCentered(fn.arg(0).to_bool()); if (fn.nargs >= 5) { // bounds have been given tu_float x0 = PIXELS_TO_TWIPS(fn.arg(1).to_float()); tu_float y0 = PIXELS_TO_TWIPS(fn.arg(2).to_float()); tu_float x1 = PIXELS_TO_TWIPS(fn.arg(3).to_float()); tu_float y1 = PIXELS_TO_TWIPS(fn.arg(4).to_float()); float bx0, bx1, by0, by1; if (x0 < x1) { bx0 = x0; bx1 = x1; } else { bx0 = x1; bx1 = x0; } if (y0 < y1) { by0 = y0; by1 = y1; } else { by0 = y1; by1 = y0; } // we've got bounds ds.SetBounds(bx0, by0, bx1, by1); } } // inform the root fn.get_root()->set_drag_state(ds); }
// setInterval(functionReference:Function, interval:Number, [param1:Object, param2, ..., paramN]) : Number // setInterval(objectReference:Object, methodName:String, interval:Number, [param1:Object, param2, ..., paramN]) : Number void as_global_setinterval(const fn_call& fn) { if (fn.nargs >= 2) { gc_ptr<as_timer> t = new as_timer(fn.get_player()); int first_arg_index = 2; if (fn.arg(0).is_function()) { t->m_func = fn.arg(0).to_function(); t->m_interval = fn.arg(1).to_float() / 1000.0f; assert(fn.env); t->m_this_ptr = fn.env->get_target(); } else if (fn.arg(0).to_object() != NULL) { as_value func; as_object* this_ptr = fn.arg(0).to_object(); this_ptr->get_member(fn.arg(1).to_tu_string(), &func); t->m_func = func.to_function(); t->m_interval = fn.arg(2).to_float() / 1000.0f; t->m_this_ptr = this_ptr; first_arg_index = 3; } else { // invalid args return; } // pass args t->m_arg.resize(fn.nargs - first_arg_index); for (int i = first_arg_index; i < fn.nargs; i++) { t->m_arg.push_back(fn.arg(i)); } fn.get_root()->add_listener(t); fn.result->set_as_object(t); } }
void sprite_stop_drag(const fn_call& fn) { //sprite_instance* sprite = sprite_getptr(fn); fn.get_root()->stop_drag(); }