im creating a drag and drop. moving a guitarest name to a target e.g draging a movieclip called slash to a dynamic text box called box_slash this is my code and i get 2 stupid errors but have been up all night and cant figure it out!
flash cs5 actionscript 3, is this code for actionscript3 i found the base for it here: http://edutechwiki.unige.ch/en/Flash_drag_and_drop_tutorial any help would be incredible as it for an assignment and im new to flash
var hits = 0;
// Register mouse event functions
slash.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
slash.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
clapton.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
clapton.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
hendrix.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
hendix.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Define a mouse down handler (user is dragging)
function mouseDownHandler(evt:MouseEvent):void {
var object = evt.target;
// we should limit dragging to the area inside the canvas
object.startDrag();
}
function mouseUpHandler(evt:MouseEvent):void {
var obj = evt.target;
// obj.dropTarget will give us the reference to the shape of
// the object over which we dropped the circle.
var target = obj.dropTarget;
// If the target object exists the we ask the test_match function
// to compare moved obj and target where it was dropped.
if (target != null)
{
test_match(target, obj);
}
obj.stopDrag();
}
function test_match(target,obj) {
// test if either one of the four pairs match
if ( (target == box_slash && obj == slash) ||
(target == box_clapton && obj == clapton) ||
(target == box_hendrix && obj == hendrix) || )
{
// we got a hit
hits = hits+1;
textField.text = "Correct! :)";
// make the object transparent
obj.alpha = 0.5;
// kill its event listeners - object can't be moved anymore
obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
// Test if we are done
if (hits == 3)
{
textField.text = "Well Done";
}
}
else
{
textField.text = "wrong! :(";
}
}
the errors are: i have highlighted the lines
| Scene 1, Layer 'Actions', Frame 1, Line 39 | 1084: Syntax error: expecting rightparen before leftbrace. |
| Scene 1, Layer 'Actions', Frame 1, Line 38 | 1084: Syntax error: expecting identifier before rightparen. |
Thankyou very much that does get rid of that error now i get
| Scene 1, Layer 'Actions', Frame 1, Line 42 | 1120: Access of undefined property textField. |
| Scene 1, Layer 'Actions', Frame 1, Line 51 | 1120: Access of undefined property textField. |
| Scene 1, Layer 'Actions', Frame 1, Line 56 | 1120: Access of undefined property textField. |
now im sure this is simple but im as im sure you have figured out im a complete noob to flash
textField.text = "Correct! :)";
textField.text = "Well Done";
textField.text = "wrong! :(";
is this something to do with an instance name?
that's not the best choice for a flash variable but, if you had a textfield named textField in the scope of your code when that code executed, you would not see an error message.
so, change the name to something else (eg, feedback_tf) and make sure that variable name matches your code and the instance name in the properties panel.
leterally just figured out that issue, proper noob mistake didnt have a capital 'F' new errors are theses ever going to stop
Use the Text > Font Embedding command to embed fonts.
ReferenceError: Error #1069: Property startDrag not found on flash.display.SimpleButton and there is no default value.
at Untitled_fla::MainTimeline/mouseDownHandler()
i would imagine that the first error doesnt matter too much, not sure on that but the second error i really havnt a clue what it means
full list of error:
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
Fonts should be embedded for any text that may be edited at runtime, other than text with the "Use Device Fonts" setting. Use the Text > Font Embedding command to embed fonts.
ReferenceError: Error #1069: Property startDrag not found on flash.display.SimpleButton and there is no default value.
at Untitled_fla::MainTimeline/mouseDownHandler()
ReferenceError: Error #1069: Property startDrag not found on flash.display.SimpleButton and there is no default value.
at Untitled_fla::MainTimeline/mouseDownHandler()
North America
Europe, Middle East and Africa
Asia Pacific