log_message("_from_code.lua executing")

----------------------------------------------------------------------------------------------------
function get_labeled_frame(charName, frameLabel)
	local ch = find_character(charName)
	
	if ch ~= nil then
		return ch:get_labeled_frame(frameLabel)
	else
		return -1
	end

end

----------------------------------------------------------------------------------------------------
function play_clip_l(clip_name, label_start, label_finish)
	play_movie_clip_ex_no_ch(clip_name, get_labeled_frame(clip_name, label_start), get_labeled_frame(clip_name, label_finish))
end

----------------------------------------------------------------------------------------------------
function play_clip_l2(clip_name, label_start, label_finish)
	play_movie_clip_ex(clip_name, get_labeled_frame(clip_name, label_start), get_labeled_frame(clip_name, label_finish))
end

----------------------------------------------------------------------------------------------------
function play_clip_lb_loop(clip_name, label_start, label_finish)
	play_movie_clip_loop_no_ch(clip_name, get_labeled_frame(clip_name, label_start), get_labeled_frame(clip_name, label_finish))
end

----------------------------------------------------------------------------------------------------

--[[
function play_movie_clip(clip_name, noChildClips)
	local ch = find_character(clip_name)
	
	if ch ~= nil then
		ch:goto_frame(0)
		ch:set_play_state(0, not noChildClips)
		ch:set_frames_for_play(0, -1)
		ch:set_looped(0, false)
		ch:set_visible(true)
	end
	
end
--]]
----------------------------------------------------------------------------------------------------
function play_movie_clip_ex(clip_name, frameStart, frameEnd)
	local ch = find_character(clip_name)
	
	if ch ~= nil then
		ch:goto_frame(frameStart)
		ch:set_play_state(0, not noChildClips)
		ch:set_frames_for_play(frameStart, frameEnd)
		ch:set_looped(0, false)
		ch:set_visible(true)
	end
end

----------------------------------------------------------------------------------------------------
function play_movie_clip_ex_no_ch(clip_name, frameStart, frameEnd)
	local ch = find_character(clip_name)
	
	if ch ~= nil then
		ch:goto_frame(frameStart)
		ch:set_play_state(0, false)
		ch:set_frames_for_play(frameStart, frameEnd)
		ch:set_looped(0, true)
		ch:set_visible(true)
	end
end

----------------------------------------------------------------------------------------------------
function play_movie_clip_loop(clip_name, frameStart, frameEnd)
	local ch = find_character(clip_name)
	
	if ch ~= nil then
		
		if frameStart ~= -1 and frameEnd ~= -1 then
			ch:set_frames_for_play(frameStart, frameEnd)
		end
		
		ch:set_play_state(0, true)
		ch:set_looped(-1, true)
		ch:set_visible(true)
	end

end

----------------------------------------------------------------------------------------------------
function play_movie_clip_loop_no_ch(clip_name, frameStart, frameEnd)
	local ch = find_character(clip_name)
	
	if ch ~= nil then
		
		if frameStart ~= -1 and frameEnd ~= -1 then
			ch:set_frames_for_play(frameStart, frameEnd)
		end
		
		ch:set_play_state(0, false)
		ch:set_looped(-1, true)
		ch:set_visible(true)
	end

end

----------------------------------------------------------------------------------------------------
function set_element_visible(name, val)
	local el = find_element(name)
	
	if el ~= nil then
		el:setVisible(val)
	end

end

----------------------------------------------------------------------------------------------------

function set_element_eh(name, func, eh_type, not_activate)
	local el = find_element(name)
	
	if el == nil then
		return
	end
	
	if not_activate == nil then
		el:setActive(true)
	end
	
	if eh_type == nil then
		eh_type = eiLeftClick
	end
	
	el:setEventHandler(eh_type, func)
end


----------------------------------------------------------------------------------------------------
function activate_element(name, val)
	local el = find_element(name)
	
	if el ~= nil then
		el:setActive(val)
		
--		if (ch->is_contain_cursor_pos())
--		ch->do_mouse_callback(event_id::ROLL_OVER);
		
	end

end

----------------------------------------------------------------------------------------------------
function move_element(name, deltaPos)
	local el = get_element(name)
	
	if el ~= nil then
		local pos = el:getPos()
		pos = pos + deltaPos
		el:setPos(pos)	
	end

end

----------------------------------------------------------------------------------------------------
function get_current_frame(charName)
	local el = get_element(charName)
	
	if el ~= nil then
		return el:getCharacter():get_current_frame()
	end
	
	return -1

end