Place RTE actions in SP.SOD.executeOrDelayUntilScriptLoaded in order to execute the specified function if the file containing it is loaded (in your case sp.ui.rte.js
):
ExecuteOrDelayUntilScriptLoaded(RTEActions, "sp.ui.rte.js");
Example:
function RTEActions()
{
var range = RTE.Cursor.get_range();
//Remaining code goes here...
SP.UI.ModalDialog.commonModalDialogClose(1, "test");
}
then declare the dialog handler like this:
function OnPopClosed() {
ExecuteOrDelayUntilScriptLoaded(RTEActions, "sp.ui.rte.js");
}