views:

442

answers:

3

Hi,

I have a Flash sprite in my Director project. Under the Properties of that sprite, under both the Member and the Sprite tabs, it has as its name "Assessment". In my Lingo script, I have the following call:

sprite("Assessment").displayGrade(75, 3, 4)

where displayGrade is a function defined in the Flash object's ActionScript as a method taking 3 numbers as parameters. However, I get an error on this line, and cannot determine why. Am I calling the Flash object's method incorrectly?

+1  A: 

Try this:

set up a container-content reference to your swf, that is the Flash main timeline:

global swfTL
on beginSprite me
swfTL = getvariable(sprite('yourFlashSprite'),'_level0',False)
end

then call

swfTL.displayGrade(75, 3, 4)

Hope it helps.

I get a compiler error of Variable used before assigning a value when I try that. The error is on the on beginSprite me function.
Elie
Hi, when I posted I assumed you were using DirectorMX: here you can find solutions for MX and MX2004: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_18541. The software version is very important.
Aside from the technote example, you could try changing the beginSprite handler with on mouseup me OR exitframe meMy suspect is that beginSprite executes before the Flash Player is instanciated
Other issues could be caused by conflicting versions: as far as I know, in Director MX you can call Flash MX (Player 6, AS 1) functions
I'm using Flash CS 3 with ActionScript 3 and Director 11.
Elie
+2  A: 

I don't know a thing about the Director side, but since this isn't resolved yet I'll ask: how are you doing things on the Flash side?

  • You said your SWF uses AS3, but AS2 and AS3 use completely different engines, so it's very possible that Director can call one but not the other, or that the method differs. Testing with a simple AS2 SWF might help.
  • Where are you defining your function in Flash? If your member Sprite is referring to a SWF, then I'd think you likely want the function to be on the main timeline of the flash file. But if your member Sprite is referring to an actual Sprite in the flash movie, then that wouldn't work, and you would need the function to be defined inside the Sprite (or the class attached to the sprite, perhaps).
  • If there's any doubt about the Flash side, have you tried to call flash methods that are built-in (and hence guaranteed to be present)? If the movie has more than one frame in its top level, you could try calling methods like play(), stop(), or gotoAndStop(n:Number). If there is only one frame then it's not so easy, as most other methods wouldn't have an obvious visual effect.

Apologies in advance if you're already sure the Flash part is okay. These are only guesses.

fenomas
Thanks for the response. I didn't develop the Flash movie, but I know it's written using AS3. The function is in the "action layer" on the first frame of the movie. Can you provide an example of another method I can call?
Elie
Sure.. I'll edit into the answer because of the length limit on comments.
fenomas
+3  A: 

Hi, I browsed a little and I found this one:

http://groups.google.com/group/macromedia.director.basics/browse_thread/thread/85203d2879267fe1?pli=1

and this too:

http://dreamweaverforum.info/director/23160-director-11-actionscript-3-a.html

Of course, you should verify by browsing the Director 11 docs.

Regards, Vyger

Thanks for the searches, it seems to be what I keep coming up with. As far as I know, there's no particular reason for our use of AS3, would an earlier version be better? Is there a way for me to just create 3 variables in Flash and then call setVariable for each one?
Elie
Not sure if a previous version could be better: that is, the links I posted seem to suggest AS3 is your problem. Anyway, I would browse Director 11 documentation to be sure "enough". It would be quite simple to build an AS2 swf file and try to call a Flash custom function.
I checked using AS 2, and I have the same problem.
Elie