Best way to create interactive text

OK - knew I’d be back! :smile:

@Mr Addy - in the example files you sent to me, there is a ‘Retina @2x’ underneath each graphic file. I assume this is for upscaling to Retina resolution displays? Could you explain how you added this to each graphic, and how it works? (Do I need, for example, two copies of each graphic with one at x2 resolution?)

EDIT - sorry - I’ve just seen that my images have this added automatically as well? How does it work? I’ve been dutifully exporting double copies of all my web images. Is this not needed?

Yeah, Hype does it for you :smile:

2 Likes

@MrAddy I am trying to build a quiz where someone could drag multiple text boxes to a column and find out the correct answer. The outline of the text box would be colored green for correct and red for incorrect. Can anyone help I have no programming experience and would like to learn how to build this type of interaction? The quiz would be a widget for a book that I am putting together.

I have the files from the spelling app. How do I get one symbol to recognize its correct location and give the user feedback that it is the correct answer?

hi,

you can’t do this without scripting. Give yourself a kick and start your project -> then ask questions to specific problems you have. I’m sure you’ll find lot of help here! But don’t expect someone to offer a ready file for you …

I’ve also posted a drag and drop example here: Checking that Multiple Drops Have Completed

1 Like

In the spelling app, you would look at the function ‘letterDropped’ and the answer would need to be a class. If you look through the spelling app, you can see each letter of the word has its own class name, so when the letter is dragged it know what class name it’s looking for. In your case, you would want to call the class ‘answer’, and the draggable element ‘questions’ and replace the names from my code to those.

I’ll try and do a mock up a little later, see if it helps, but as above, to learn is to do, so ill do :smile:

@MrAddy @h_classen Thank you for your feedback. I didn’t mean to imply that I wanted anyone to do the work for me or to script it for me. I can build the text box and drag the text box but the problem is I don’t know the string of code or the Javascript function to make one text box recognize that where it is dragged to is the correct answer. I can build the rest just needed the staging point for the Javascript. Thanks again for all of your help.

@MrAddy @h_classen Here is what I have been able to do thus far. The background is not changing. Roles test.hype.zip (36.4 KB)

checkWhenDropped.hype.zip (59.8 KB)

tried to simplify it.
drag the questionelement to an answer, then drop it.
if the answer is right the answerelement will get green …

check the js and the answerelements class to see how it works.

hope this’ll work for you to get further

@h_classen This is great! How do I change it so that when the box is dropped it stays in the place because I want the user to see all of their answers.

with use of hye:
create relative timelines that shows the way fo the dragcard to each answercard.
if the dragcard is dropped execute the timeline that matches the drop.
the id of the answercard will help you to identify the correct timeline …

guess you’ve got all you need to know in the existing js-part

Marko, what you have done, which is a common mistake, is copy the code without actually understanding what it’s doing.

You need to have a basic understanding of variables, what a variable is, and how to assign an object, element, or string. In this case element.

In your example you have a variable called ‘home’, but you do not define what ‘home’ is, and so the code would not work. You also did not include jQuery library.

Nobody can do work with code without understanding the very basics. If you unsure what each line of code does, its best to ask for a detailed explanation.

In my spelling example, once a element is close enough to the box, it then triggers a different response to the one when it’s not.

var answerElement = $(element).closest('.HYPE_scene').find('.answer');

var answerBox = document.getElementById($(answerElement).attr('id'));
	
var question = element.getBoundingClientRect();
var answer =  answerBox.getBoundingClientRect();

if(Math.abs(question.left - answer.left) <= 30 && Math.abs(question.top - answer.top ) <= 30) {
	
	// Close enough
	element.style.display = 'none';
	var symbolInstance = hypeDocument.getSymbolInstanceById('answer_A');
	symbolInstance.startTimelineNamed('Main Timeline', hypeDocument.kDirectionForward);
			
} else {
	
	// Not close enough
	console.log('element is NOT close enough');
	hypeDocument.startTimelineNamed('returnQ', hypeDocument.kDirectionForward)
}

This is all the code you need at the very basic, using relative timelines to return the question.

Roles test_1.hype.zip (110.2 KB)

2 Likes

@MrAddy Thank You. I am trying to learn.

This thread has become a bit complex – Does anyone want to create a separate thread for this to distill the best examples?

Dear MrAddy, apologies for throwing this topic back into discussion after its last reply over 3 years ago! I have used your Spelling App hype project to create my own however i am struggling!
I need to create a drag and drop exercise where names of presidents need to be matched up to boxes under photos.

I have stripped away code that isnt needed and kept the letters of alphabet which i thought i could just rename letter A to Abraham Lincoln, letter B to John F. Kennedy and so on.

However when i start to rename the Letters symbols the click and drag function breaks - your help will be greatly appreciated, thank you

Navneet_Spelling App.hype.zip (116.2 KB)

The issue is the line of code that iterates through the solutions:

$.each($(element).closest('.HYPE_scene').find('.home_' + element.innerHTML+':not(.used)'), function(ind, homes) {

There’s a few things to note - you are using the element.innerHTML to help name a class. This means:

  • Your class name of the drop zone needs to match the HTML of the drag element. In your document the class name is still home_A. You would need to change it to home_Abraham Lincoln to match, but:
  • The class name must be valid, and you can’t contain spaces in a class name.

So it may be better to not use a innerHTML approach and identify drag/drop targets either based on a lookup table that will associate innerHTML to class names or another approach.

1 Like

Thanks so much for your help jonathan! super star!!!

1 Like