Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass variable to ActionScript from JS and perform action

Status
Not open for further replies.

knuckle05

Programmer
Dec 17, 2001
247
CA
Hi All,

I'm really new to Flash but I'm getting by okay so far.

I've created a "seek bar" that I will be using to control my media player on my website.

Basically, I would like to pass a variable from my page to my Flash movie to tell the movie where to place the cursor.

How could I then move the cursor to another position?

So basically I'd like to know:
1) how to pass a var to ActionScript from js
2) how to move my object once said var has been received

thx
 
Thanks Bill,

Pretty straight forward.

Any idea how I would then be able to perform an event in my Flash movie so that I could move my cursor along my timeline according to my variable value? Thx
 
I think what I would ned to do is call the StartDrag() function???
 
im not quite sure what you mean

if by moving along the timeline you mean jump to a frame then thats easy.

or do you mean the mouse cursor?
 
If your cursor is a movie clip, then just set it's position within according to the variable...

onClipEvent(enterFrame){
this._x = _level0.my_var;
}

_level0.my_var, being the value passed. Regards,

oldman3.gif


Don't worry, if my reply is wrong, BillWatson will clean it up for me!
 
Thanks guys,

I appreciate the help.

Yes, my cursor is a movie clip and basically I just want to change the x coordinate.

I'm only using one frame in my movie since I don't need any animation.

I will try it out!!

 
The enterFrame will constantly loop, so if your variable doen't change then an on load event would do!

onClipEvent(load){
this._x = _level0.my_var;
}

And it might be a good idea to make your movie a few frames long (5), and have a stop action. Provision so that the variable is read before the clip's position is set.
Regards,

oldman3.gif


Don't worry, if my reply is wrong, BillWatson will clean it up for me!
 
Well, I seem to have it working with no evident bugs, however there must be a logical error somewhere.

Here is my code for the OnClipEvent of my cursor (movie object)

onClipEvent (load) {
<not set yet> = &quot;&quot;;
}
onClipEvent(enterFrame){
this._x = _level0.intCurPos;
}


No errors are diplayed, but the cursor is not moving. Why is it necessary to create many frames (5) if I don't really need them? And what should I put in them?


 
Are you testing this through the html?

Do you have a stop action(); on your 1 frame main movie?

If you add a trace action on this frame, what do you get?

trace(_level0.intCurPos);

Regards,

oldman3.gif


Don't worry, if my reply is wrong, BillWatson will clean it up for me!
 
i dont know how you are loading the variables . if you are not using loadvars then that may be the problem. you are trying to set the value before its loaded. loadvars takes care of this problem for you.
 
Hi,

Here is my JS function from my HTML page which passes the var to my Flash movie

function mySetMediaPosition(thePosition){
//*******UPDATE FLASH TIMESCALE*********
document.movie.SetVariable(&quot;intCurPos&quot;, thePosition );
}

In my clip event I placed

onClipEvent(enterFrame){
trace(_level0.intCurPos);
this._x = _level0.intCurPos;
}

I do not receive any message or errors however. I'm getting close though, I can feel it. Any ideas?
 
The clip is not nested,

What should I see when I use the Trace function? Should I be getting a popup like in JavaScript?
 
The trace action should open up the Flash output window, and you should see your variable's value if it was passed, or &quot;undefined&quot;, if it wasn't. Regards,

oldman3.gif


Don't worry, if my reply is wrong, BillWatson will clean it up for me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top