Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  Viewpoint Tips, Tricks & Hacks    Trigger Actionscript in a Flash Texture
Page 1 2 

Moderators: e_phoenix13
Go
New
Find
Notify
Tools
Reply
  
5-star Rating (1 Vote) Rate It!  Login/Join 
Member
Posted
I started this thread because for the life of me, I cannot find out how to talk to or activate actionscript in a swf texture. Maybe I am not wording ir correctly, but I figure if someone answers this it will be easier to find this information by having a thread for it.

So the question is, If I have a SWF texture on a model, and I want to tell it gotoAndPlay(5); from OUTSIDE the viewpoint scene (for example using a plain old html form button), how do I accomplish this communication? I have found broken links to things that may have led me to the answer, but nothing clear and solid. I have been sifting though the VP documentation, but thats like sifting through a dictionary for how to write an article for YM and get it published. :P
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
Member
Picture of DavidR
Posted Hide Post
The following was taken from the Master of Viewpoint library on Rich3D. We will make a few changes to make this more apparent. Good luck!
DavidR

Scripting FLASH from outside
What can you do?
- Get/Set values assigned to Edit Text
- Get/Set movie clip properties (positions, rotation, scale, alpha…)
- Access all the Action Script objects (Date,Math,MovieClip,String …)
- Access all the variables defined in ActionScript
- Access all the methods and functions defined in Action Script
- Access to the whole flash tree (DOM)
How?
In order to do that, we use the property system.
All the properties will be flash content dependant, so, to differentiate flash TimeElem properties from flash internal properties, we added the keyword “SWF”
Example
<MTSSetProperty Target="myFlash.SWF.root.frank._rotation" Value="45" />
myFlash is the flash TimeElem
SWF is the special keyword to access internal flash elements
root.Frank.rotation : specified exactly like in action script.
Syntax
1)sensitive
In action script, access to variables, objects… is not case sensitive, it will be the same in SetProperty for elements specified after SWF.
<MTSSetProperty Target="myFlash.SWF.root.Frank._Rotation" Value="45" />
<MTSSetProperty Target="myFlash.SWF.Root.frank._rotation" Value="45" />
both are valid and the same.
However, the general recommendation is to work as if it were case-sensitive (use _rotation above – properties are not capitalized), because actionscript is based on ECMAscript, which IS case-sensitive. The current lack of case-sensitivity is for
backwards compatibility with Flash 4. Some elements introduced afterwards (like onClipEvent) rely on case, and future syntax elements may as well.
2)root
Like in ActionScript, the “_root” object is not compulsory - it indicates the object’s location in the movie.
"myFlash.SWF._root.frank._rotation" is equivalent to "myFlash.SWF.frank._rotation", and assumes frank is located at the root level of the movie. _root is used in Flash commonly because it is possible to play one Flash movie inside another. In the event you developed a movie with a number of variables, using _root as a location for variables would help to insure your movie would work even if played inside another swf.
3)objects
In ActionScript, to access objects, the syntax is :
Object.method(arg1,arg2,…);
From properties, it will be exactly the same, you can do :
(a) <MTSSetProperty Target="myFlash.SWF.root.gotoAndStop(2)" Value="" />
Also, another syntax can be used here to be able to animate the Value
(b) <MTSSetProperty Target="myFlash.SWF.root.gotoAndStop()" Value="2" />
Why both syntax available :
- with (a) you can access methods with multiple arguments “myFlash.SWF.math.Tan2(2.3,1.6)”
- with (b) you can animate with for example keyframes the values passed to the methods.
MovieClip
With DOM, all the movie clips in your flash file can be accessed from property system:
"myFlash.SWF.root.clip1.subClip2.subsubClip3”
Properties available :
yes "_x",
yes "_y",
yes "_xscale",
yes "_yscale",
no ePropertyCurrentFrame
no ePropertyTotalFrames
yes "_alpha",
yes "_visible",
yes "_width",
yes "_height",
yes "_rotation",
no ePropertyTarget
no ePropertyFramesLoaded
yes “_name” no ePropertyDropTarget
no ePropertyUrl
yes “_highQuality”
no ePropertyFocusRect
no ePropertySoundBufTime
Methods available :
"attachMovie()"
yes "duplicateMovieClip()"
yes "getBounds()"
yes "getBytesLoaded()"
yes "getBytesTotal()"
"getURL()"
yes "globalToLocal()"
yes "gotoAndPlay()"
yes "gotoAndStop()"
yes "hitTest()"
yes "loadMovie()"
"loadVariables()"
yes "localToGlobal()"
yes "nextFrame()"
yes "play()"
yes "prevFrame()"
yes "removeMovieclip()"
yes "startDrag()"
yes "stop()"
yes "stopDrag()"
yes "swapDepths()"
"unloadMovie()"
yes "goto"
Objects
Date
Methods available:
"getDate()"
"getDay()"
"getFullYear()"
"getHours()"
"getMilliseconds()"
"getMinutes()"
"getMonth()"
"getSeconds()"
"getTime()"
Math
Methods available:
"abs()",
"acos()",
"asin()",
"atan()",
"atan2()",
"ceil()",
"cos()",
"exp()",
"floor()",
"log()",
"pow()",
"random()",
"round()",
"sin()",
"sqrt()",
"tan()"
"max()",
"min()",
String
Methods available:
"fromCharCode()",
"charAt()",
"charCodeAt()",
"concat()",
"indexOf()",
"lastIndexOf()",
"slice()",
"split()",
"substr()",
"substring()",
"toLowerCase()",
"toUpperCase()",
"toString()",
"valueOf()"
Array
Methods available:
"concat()"
"join()"
"pop()"
"push()"
"reverse()"
"shift()"
"slice()"
"sort()"
"splice()"
"toString()"
"unshift()"
Edit Text
- All the variables declared in actionScript are available in the property system.
When an edit text is added to the scene, if a variable name is specified, by accessing this variable, it will be possible to set/get the value of an edit text.
Further Reference
For specific actionscript syntax questions, check Macromedia’s actionscript dictionary:
http://www.macromedia.com/support/flash/action_scripts/...onscript_dictionary/
Actionscript the Definitive Guide ( available from http://www.oreilly.com) is probably the most comprehensive print resource.
Ongoing notes on supported Flash-in-VET functionality are available here:
http://cole.viewpoint.com/qatech/test_content/flash/MT/...d_functionality.html
(We’ll change that to an external URL when we have one.)
 
Posts: 308 | Location: Atlanta Georgia | Registered: January 24, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Nice find, thanks for sharing David! I am disecting this, now it is only a matter of figuring out how to put it together. I think I am headed in the right direction, but I have something wrong in my approach, as I cant get what I have figured out to work. =P

Taking all these resources, and putting them together in a clear, concise manner that reads like it wasn't written by a developer, would be an awesome resource to have (hence my question about getting a Viewpoint for dummies book written in the future, vs just a dictionary of technical jargon, which is the main instructional resource being used right now over here).

We use Flash a lot at our studio here, so we have a pretty good understanding of it. It always comes down to figuring out though, how these things work with VET, that throws us for a loop and sends us into the "test everything under the sun for 2 days" mode before we can figure it out (or get an answer from Anup or Admin that enlightens us).
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Still trying to figure this one out, if anyone wants to take a stab at it. That info was nice David, but in typical Viewpoint fasion, is lacking the solid details to piece the info together to make it useful. For example, so far this is what I have, and is derived from piecing together snipets of semi-related examples found around the board:

<MTSAction Name="decal1" Type="Script">
<MTSSetProperty Target="MTSTexture.desmo_rr_color_1.SWF_root.gotoAndStop(3)"/>
</MTSAction>

<MTSInteractor Name="test1">
<MTSHandle Event="load_decal_1" Action="decal1"/>
</MTSInteractor>

<MTSTimeElem Name="desmo_rr_color_1_VectorAnim" Type="SWFView" Path="Desmo-RR_Color_1.swf" Loop="0" >
<Target Name="MTSTexture.desmo_rr_color_1" />
</MTSTimeElem>

From the stuff I have found, to ME, it looks correct, but like mentioned, there is no solid complete example of how to do this, I just have found little tidbits of info to lead me in this direction. Problem is, though, is everytime I find an example it is so short, and only like a piece of the whole, that it leaves the rest to interpretation.

Im using the following on the hmtl page to try and trigger the action:

<input name="test1" type=button value="Test1" onclick="vmp.PostEvent('load_decal_1')">

What is wrong?
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Hi,

A small correction to your code. It should be....
<MTSAction Name="decal1" Type="Script">
<MTSAssignProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.gotoAndStop(3)"  Value="" />
</MTSAction>


This should work.
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Thanks Anup for the reply. Unfortunately that didnt do it, still no change when I hit the button.

The scene doesn't need to be redrawn does it?
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Attached is a working sample file.

Hope this helps.

Zip/GZ archiveFlash_Commands.zip (13 KB, 16 downloads)
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
quote:
Originally posted by e_phoenix13:
Attached is a working sample file.

Hope this helps.


Thanks, deconstructing now!
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
quote:
Originally posted by e_phoenix13:
Attached is a working sample file.

Hope this helps.


As always, your da man! Thanks, this got me going in the correct direction, I can now interact with my SWF's! I noticed one thing I had different was I didn't have the < On="1" > attibute on the MTSTimeElem in my original file, AND I wasn't using the javascript snipet for the timeout. One of those changes did it though, and I thanks you!
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Hi again :P

Ok so I can talk to my SWF texture now, but I might have the syntax wrong on something. I set it up first to be able to gotoAnPlay a frame, and on the frame (in the swf texture) I have an empty MC and some actionscript that will load a movie into that empty MC. That works fine.

My problem is, however, that if I try using the loadMovie in my MTX, rather then gotoAndPlay, I dont get anything. To clarify, here is my code:

Non-working:
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadMovie(decal_1_left_diadora.swf, empty_mc_1)" Value="" />
</MTSAction>

Working:
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.gotoAndPlay(2)" Value="" />
</MTSAction>

So, if I havent confused you yet, I want to use loadMovie in the action, this way I can set up multiple instances (im loading decals on to the bike)rather then using gotoAndPlay and have the load movie within the SWF.

Thanks for the help.
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Try these options...

OPTION 1: Try putting single quotes to the SWF file name you are loading....
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadMovie('decal_1_left_diadora.swf', empty_mc_1)" Value="" />
</MTSAction>


OR

OPTION 2: Write the following function on the first frame of your flash movie.
function loadDecal(decalFileName) {
    loadMovie(decalFileName, empty_mc_1);
}


Following will be your VET Action:
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadDecal('decal_1_left_diadora.swf')" Value="" />
</MTSAction>


Let me know if any of these work.


Cheers,

Anup
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Hi Anup, thanks for the speedy responce.

Unfortunately, neither one of these methods worked.

Here is my function in flash:
function loadDecal(decal_1_left_diadora) {
loadMovie(decal_1_left_diadora.swf, empty_mc_1);
}

I cant put loadDecal(decal_1_left_diadora.swf) because if I do, it causes an AS error and just ignores everything else.

I thought maybe the single quoted option number 1 would have worked, but it was a no go also.

Anywho, yeah for some reason with option 2, I did it exactely as you had it, cleared the directory and re-uploaded everything to the server, cleared my temp internet files (just to make sure) then ran it a number of times and still nothing. The scene refresh's, but the loadmovie isnt working. From the example that dave posted, it reads like what I have will work, but you know how that goes :P.
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Your flash function should exactly look like I wrote in my post above. DO NOT put the actual file name there. Its just a variable to pass an arguement to that function.

Update it as follows to avoid confusion...
function loadDecal(newDecal) {
    loadMovie(newDecal, empty_mc_1);
}


Try OPTION 2 with the function as written above and let me know.


Cheers,

Anup
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Hi Anup.

Yeah sorry I misinterpreted that. Anyways, I changed it to what you have, still no go, it doesn't work.

Im repeating my code here so you can see what I have:

The action:
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadDecal('decal_1_left_diadora.swf')" Value="" />
</MTSAction>

The interactor (this stuff works fine):
<MTSInteractor Name="test1">
<MTSHandle Event="load_decal_1" Action="label_1"/>
</MTSInteractor>


The flash function:
function loadDecal(newDecal) {
loadMovie(newDecal, empty_mc_1);
}


And I use this on the HTML page, like you showed me:
function changeTexture(msg) {
vmp.PostEvent(msg);
setTimeout('vmp.Render()', '500');
}

The button:
<input name="test1" type="button" value="Test1" onClick="changeTexture('load_decal_1');" >


Looks right... : /

This message has been edited. Last edited by: Media Outbreak,
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
I figured it out!!!

Ok so here was the solution. I keep reading in places where it says loadMovie is not supported in the MTX, then others that say it do (the viewpoint rich media authoring guide says it does not).

So, I changed some stuff around, made it load the MC in the function within the SWF file, rather then call loadmovie in the MTX. Here is the final code:

<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadDecal()" Value="" />
</MTSAction>

And my flash function:
function loadDecal() {
loadMovie("decal_1_left_diadora.swf", empty_mc_1);
}

Booya!

Thanks Anup for the help, it was your tip on creating the function that led me to the sollution.
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
But in this way, you will have to create one function for every decal. Thats kind of messy. I am working on to find a better solution. Will keep you posted.
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
quote:
Originally posted by e_phoenix13:
But in this way, you will have to create one function for every decal. Thats kind of messy. I am working on to find a better solution. Will keep you posted.


Cool, thanks for your support man, we appreciate it.
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
Ok. Here is the solution. One Flash function does it all. Just keep chaning the SWF file name in the MTX Action.

Modify the function on the first frame as...
function loadDecal(newDecal){
	var newDecalName = newDecal + ".swf";
	loadMovie(newDecalName, holder_mc);
}


Modify the action in MTX file to...
<MTSAction Name="label_1" Type="Script">
<MTSSetProperty Target="MTSTimeElem.desmo_rr_color_1_VectorAnim.SWF._root.loadDecal('decal_1_left_diadora')" Value="" />
</MTSAction>



Hope this helps.


Cheers,

Anup
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
EnIgMaTiCScOrPioN
Member
Picture of e_phoenix13
Posted Hide Post
A better optimized solution. I would go with this.

One function in Flash on the first frame:
function loadDecal(newDecal){
	var newDecalName = newDecal + ".swf";
	loadMovie(newDecalName, holder_mc);
}


One Action in MTX:
<MTSAction Name="change_decal_action" Type="Script" >
	<MTSAssignProperty Target="MTSTimeElem.cube_textures_loader.SWF._root.loadDecal();"  Value="decal_name" />
</MTSAction>


Interactor in MTX handles messsages and SWF file names:
<MTSInteractor>
	<MTSHandle Event="texture_1_msg" Action="change_decal_action" decal_name="cube_textures_1" />
	<MTSHandle Event="texture_2_msg" Action="change_decal_action" decal_name="cube_textures_2" />
</MTSInteractor>



Working files attached.


Cheers,

Anup

Zip/GZ archiveFlash_Load_Movie.zip (23 KB, 13 downloads)
 
Posts: 557 | Location: India | Registered: February 12, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Wow, nice clean sollution Anup, thanks!

Question on this. I actually have 4 empty MC's on the stage in different spots on the model so that they can load in and choose decals on 4 different spots on the bike at the same time. So if I understand this correctly Im going to need to set up 4 functions and 4 actions all together, one for each of the empty mc's decal spots?

I like this, and learn a lot everytime you help me with these sollutions! Thanks again man!

Oh and I wanted to mention, the reason I needed to do it like this is I am stacking textures (as you might have been wondering why I wasnt using hte sollution for swaping textures we discussed a few months back). I have it set up now so that the different base textures are on different frames in the base SWF. This way they can choose from all kinds of basic and advanced paint jobs first, then add the decals on over that.
 
Posts: 105 | Registered: March 16, 2007Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community Page 1 2  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  Viewpoint Tips, Tricks & Hacks    Trigger Actionscript in a Flash Texture