• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Flash drag and drop not finding targets in Captivate

New Here ,
Jun 09, 2010 Jun 09, 2010

Copy link to clipboard

Copied

I created a drag and drop game in Flash CS4 using Actionscript 2 which allows you to pull clothing onto a stick figure. If you get the clothes in the right place, over the target, then they stick, if not they return to their original position. It works fine but when I open it in Captivate 4 the targets no longer hold the objects. No matter where you place the clothes icons they will return to their original position.

I have captivate set up for the correct Actionscript and the fps in captivate and the swf are the same. I've included the code I wrote below. Please help if you have any answers as to why this is happening.

shirt_mc.onPress=function(){

startDrag(this);

}

shirt_mc.onRelease=shirt_mc.onReleaseOutside=function(){

stopDrag();

if (this._droptarget == "/targetShirt") {

this.onTarget=true;

_root.targetShirt.gotoAndStop(2);

}else{

this.onTarget=false;

_root.targetShirt.gotoAndStop(1)

}

}

shirt_mc.myHomeX=shirt_mc._x;

shirt_mc.myHomeY=shirt_mc._y;

shirt_mc.onMouseDown=function(){

//this variable tells us if the mouse is up or down

mousePressed=true;

}

shirt_mc.onMouseUp=function(){

mousePressed=false;

}

shirt_mc.onEnterFrame=function(){

//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

// then move the MC back to its original starting point (with a smooth motion)

if(mousePressed==false&&this.onTarget==false){

this._x-=(this._x-this.myHomeX)/5;

this._y-=(this._y-this.myHomeY)/5;

}

}

pants_mc.onPress=function(){

startDrag(this);

}

pants_mc.onRelease=pants_mc.onReleaseOutside=function(){

stopDrag();

if (this._droptarget == "/targetPants") {

this.onTarget=true;

_root.targetPants.gotoAndStop(2);

}else{

this.onTarget=false;

_root.targetPants.gotoAndStop(1)

}

}

pants_mc.myHomeX=pants_mc._x;

pants_mc.myHomeY=pants_mc._y;

pants_mc.onMouseDown=function(){

//this variable tells us if the mouse is up or down

mousePressed=true;

}

pants_mc.onMouseUp=function(){

mousePressed=false;

}

pants_mc.onEnterFrame=function(){

//all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

// then move the MC back to its original starting point (with a smooth motion)

if(mousePressed==false&&this.onTarget==false){

this._x-=(this._x-this.myHomeX)/5;

this._y-=(this._y-this.myHomeY)/5;

}

}

TOPICS
Advanced

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 09, 2010 Jun 09, 2010

Copy link to clipboard

Copied

I created a similar drag and drop, in order to create a matching activity that allowed for partial points to be earned.

Also made it in Flash CS4 using AS2.

The issue is that once you bring it into Cp, the relatives paths to your targets change.

Your movieclip will be inside a specific slide movieclip which is inside the main timeline clip (possibly more depending on how you embedded it).

[On a sidenote, since the slide paths are created during the output, the target will change if you only preview a portion of your project.

In other words, if it is normally on slide 10, but you are only previewing 5 slides at a time, your paths won't work.]

I could try to explain how to account for the levels down to your clip, but honestly I think the easier solution is to add a trace statement to your flash file that tells you what you dropped your object on.  Then once you know the proper name for your target, you can go back and code for it.

I hope that made sense.  This is what the path turned out to be in my case:

/slide[x-1]__color_mc/[object name in cap]/m_swf_mc/content_mc/def1_mc/def_txt

Pretty ugly huh?

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 09, 2010 Jun 09, 2010

Copy link to clipboard

Copied

This is an interesting issue.  I am in the process of creating a very large project that involves HEAPS of flash games, very similar to the one decribed in the OP.  In fact, I have an almost identical game, where the user is asked to dress a man with the appropriate safety gear!!

To this point, I have had huge difficulties with Captivate 4 and Flash interactive animations.  Not as you describe, but just very strange behaviour.  My current issue with the animations is that if I place one animation in the project, it works fine, but then I add another one and the first one just jumps to the completed state!!! I remove the one I just added and hey the first one works again.  It is incredibly frustrating to spend several hours making an interactive game that works perfectly in Flash, to only then discover Captivate will not run it correctly in certain situations.

Has anyone else had thses issues with Captivate 4?  Will captivate 5 have a cleaner interaction (if that is the correct word) with flash games?

Anyway, back to the drawing board as the frustration continues!

tristan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 09, 2010 Jun 09, 2010

Copy link to clipboard

Copied

Hi Guys,

To be honest, using _root in AS code should be avoided if possible. You should try to use relative references instead of the root. However, for those of you using AS2, try setting the _lockroot property to true. This will most likely solve your issues.  You set this property at the top of your frame in your fla file. In AS3, lockroot has been remove but it's behavior is implemented by default.

So give this a try to see if it solves the problem.

Whyves

____________________________

www.flash-factor.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

I agree with the avoiding _root.  I was able to resolve my issues with the drop target with just finding the correct relative path.

I have multiple swf's on just about every page of my courses tracking and interacting in different ways.

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

Hi all,

Thanks for the informative replies.  My main issue seems to be when adding animations.  For example (I have included one below
).  I add this animation to my project and it runs perfectly.  I then add another, very similar animation, and the sound dissapears completely in the previous one! I remove the one added, preview the project again and the first animation works again!

The only access I make to Root is through the successful click on the otherTARGET, that tells captivate to move to the next slide.  Could this be the root (exuse the pun) of my problems?

Any help appreciated!

stop();

var target:Array=new Array(likelyTARGET,otherTARGET,other1TARGET);

addListners();

var more:Sound = new consequencefocuspeople();
var less:Sound = new consequencemoreserious();


function addListners(){
for (var i in target) {   
target.addEventListener(MouseEvent.CLICK, onClick);
}
}


function onClick(event:MouseEvent):void
{
var item:String = event.target.name;
switch(item)
{
  case "otherTARGET":
 
     var mainmov:MovieClip = MovieClip(root);
      mainmov.rdcmndNextSlide = 1;
  break;
 
  case "other1TARGET":
  removeAllEventListner()
  var soundChannel:SoundChannel = more.play();
  soundChannel.addEventListener(Event.SOUND_COMPLETE, soundComplete);
  break;
 
  case "likelyTARGET":
  removeAllEventListner()  
  var soundChannel2:SoundChannel = less.play();
  soundChannel2.addEventListener(Event.SOUND_COMPLETE, soundComplete);
  break;
}


}

function soundComplete(event:Event):void {

addListners()

}

function removeAllEventListner()
{
for (var i in target)

  target.removeEventListener(MouseEvent.CLICK, onClick); 
}
}

thanks,

tristan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

This problem continues to frustrate:

I insert one animation in a new project.  Preview Project, no issues.  I add another slide, add another animation and bang, either the first one dissapears/jumps to end state and the second one does not work, or sometimes works!  I delete the one just added and again, the first one works.  I have tried adding other animations, to a total of around 10, then perhaps 1,2,3,5,7 will work and the others will dissapear/not work!!!

I am not doing anything radical here.  The animations are fairly basic, click on/drag drop etc etc.

Any ideas of what I am doing wrong?  Theres seems to be a conflict somewhere, but im having no luck in finding it!

Thanks,

Tristan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

Can you put fla files and captivate project somewhere? Otherwise, it's very difficult to help.

Whyves

_________________________

www.flash-factor.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2010 Jun 10, 2010

Copy link to clipboard

Copied

Hi,

Thank you so much for any help!

I have uploaded the sample file here:

http://www.safetynaction.co.nz/captivate/module3.cptl

In this example, although there are many 🙂

Slide 1 and 2 work fine, slide 3 the sound does not work, or it seems none of the clicks work, although the mouse icon appears onmouseover, same issue with slide number 5 and slide number 6 just jumps to its complete state i.e. all interaction is skipped 😞 and slide 7 works!!!

Thanks again to one and all for the continued help and support!

Tristan

putting fla's up asap

ok:

Fla's here:

http://www.safetynaction.co.nz/flash/flafiles.zip

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

Tristan,

I could not download your files but I had a question for you, are you using the pre-built components (e.g. check box compoenent, etc) or is everything hand coded/created?

The reason I ask is that I had an issue for a while whenever I had embedded more than 1 swf that used the same pre-built component.

They would end up disabling each other.  Eventually solved it by eliminating the components and doing a simple scripted version for each.

Just a thought.

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 11, 2010 Jun 11, 2010

Copy link to clipboard

Copied

Hi Russ,

No, I am not using anything like that, everything is hand coded, but thanks for the suggesstions.  This is getting so frustrating now!  I have quite a large project to deliver, and everything is complete apart from piecing it all together in Captivate!

It is such a strange problem.  I reallly am quite stuck at this point!

Thanks again,

Tristan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 12, 2010 Jun 12, 2010

Copy link to clipboard

Copied

Hi Tristan,

When you run the Captivate project using the Flash Debug Player, a few exceptions pops up. These exceptions prevents some part of the code to run and thus the strange effects you are seeing. I suggest that you install the plugin for the debug player so you can monitor the exceptions. Then, configure your fla to use the technique I explained on my blog. This way, you will be able to track what's going on in your code. One of the error I found was in your module 2 - game 2. The variable "nolonger" used in one function does not exist and thus causes an error. Some of the thing I advise:

  • Import swf instead of fla files. This way, you'll be able to update the swf from the library easily.
  • Your fla files are configured for Flash Player 10. I think it would be wise to publish for flash player 9.
  • You should monitor for the event ADDED_TO_STAGE before adding the initial listeners. I suspect that this could be the major cause for your problems. Sometimes I get an exception for objects not existing in the addListeners function. If you try to add listeners on clips not yet created, it will cause exceptions.
  • Remember that all animations are loaded initially and start playing from page 1. So, it is possible that an animation has finished playing before you get to it.
  • Some people have gone over similar issues by loading the animation in a loader. Take a look on Micheal's site: www.cpguru.com.
  • You can try to check on the "Synchronize with project" option in the Option tab of the Animation dialog.

Good luck!

Whyves

___________________________

http://www.flash-factor.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 13, 2010 Jun 13, 2010

Copy link to clipboard

Copied

LATEST

Hi Whyves,

Thank you so much for taking the time to look at this for me.  Very kind and appreciated!

For now (due to pressing deadlines), I have moved away from Captivate, and designed a module in Flash to load the published .swf files, so as to give a similar look and feel that captivate gives.  Eventually however, the project will have to be migrated back into Cpativate (hopefully captivate 5). So I will start testing these ideas over the coming weeks.  It gives me an excellent starting block, so thanks again!

Take care and once again THANK YOU!

Tristan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources