dcsimg
A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: javascript/actionscript

Hybrid View

  1. #1
    Member
    Join Date
    Jan 2001
    Posts
    54

    Post

    I am a newbie to javascript and actionscript. I am in nedd of some code that is compatiable to 3dfa to set a timer function to delay an instance of an object (ie; place and object wait a predetermined length of time and move the object to its next position). I would be impractiable to do this with keyframes as I hope to use this function with many objects.

    I tried doing this with a frame animation but I could not set properties or assign variables to the objects within the animation.

    Anyone who can provide code to set a times function has my thanks in advance!...Tomkat42

  2. #2
    Member
    Join Date
    Feb 2002
    Posts
    71

    tried move thru key positions?

    Have you tried the move-through-key-positions event? Each delay has a limit of 10 seconds, but it's a quick and easy way to do what you're saying, assuming a delay of 10 seconds is adequate.

  3. #3
    Member
    Join Date
    Feb 2002
    Posts
    71

    list of actions

    Another solution might be to use the list of actions element. It runs in the background; you can set a
    variable = timer();
    call in a javascript within the list of actions to get your timing;
    divide by 1000 to get seconds: use the
    round(timer()/1000);
    expression to get the nearest second.
    You can use if /else conditions to set the timer's boundaries, and then put the element.position.x and element.position.y values inside each if/else condition.
    See some of the answers to my questions about timers below to get other ideas on how to set timers.

  4. #4
    Member
    Join Date
    Jan 2001
    Posts
    54
    Thankes JDE...I got it to work by calling a javascript via a list of actions. Everything works fine in 3dfa but when exported it will not work in a browser...Any suggestions? Here is the code I used....

    var i =i;
    i=0;for (i=0; i<100;i++)
    {
    debug i
    )
    a.position.x=a.position.x+5;

  5. #5
    Member
    Join Date
    Feb 2002
    Posts
    71
    Hmm, I'm new to javascript, so this is probably the blind leading the blind. Does your for loop represent your timer? I was thinking of using the timer() expression available from within 3dfa javascript. Is the code exact? You need to use a } closing brace, not ). I would also use a ";" after the debug statement. I had trouble with some browser issues, and traced them back to some small syntax errors that 3dfa seemed to forgive, but the browser wouldn't.

  6. #6
    Member
    Join Date
    Jan 2001
    Posts
    54
    the ) instead of the } was a typo on my part within my post here not in my script. As far as the ; after the debug, if the semicolon is included the actual timer count function does not work I just get a move of the continous object. If I leave out the ; after debug the count and delay works fine...BUT ONLY WITHIN #DFA and not when exported. This is not the first time I have ran into this export thing. If anyone else has any comments or suggestions please feel free to offer them as I am stuck here.

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    looping in 3dfa's JS

    Originally posted by tomkat42
    the ) instead of the } was a typo on my part within my post here not in my script. As far as the ; after the debug, if the semicolon is included the actual timer count function does not work I just get a move of the continous object. If I leave out the ; after debug the count and delay works fine...BUT ONLY WITHIN #DFA and not when exported. This is not the first time I have ran into this export thing. If anyone else has any comments or suggestions please feel free to offer them as I am stuck here.
    I've found that looping as a timing action within 3dfa's javascript not to be a good way to pause.

    use timer() and let the list of actions do the looping for you. In your main movie set the variable start=0 and delay=10 then in the list of actions do this

    start=timer()/1000;

    if (timer()/1000=>start+delay)
    {
    Do what ever;
    }

    This is off the top of my head beware typos.
    Be sure your list of actions is called frequently, maybe 20 instead of 10 times/sec


  8. #8
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    Hello tomkat42,

    Your code example should work except for the debug statement. This only works in the preview mode and never in the browser.

    With regards to the statement
    a.position.x = a.position.x + 5;
    this should work. May I suggest that you double check that 'a' has been assigned the element via the 'element()' method. If not then add
    a = element("your_element_name_here");
    to your code.

    Also, I've been experiencing problems if using the 'return' statement outside of functions. Try to avoid the use of this statement unless it is used inside a function. Otherwise, you'll find that code is not executed and/or skipped in an Actions element.

    For delay (it that's its intentions) I would go with Bret's suggestion as there is currently a memory leak with the use of the for/while statements which will end up causing your movie to slow right down unless you refresh your browser.

    HTH.

    Cheers,
    Ed


  9. #9
    Member
    Join Date
    Jan 2001
    Posts
    54
    the code that bret posted
    start=0 and delay=10 in main movie and a list of actions calling.............

    start=timer()/1000;
    if (timer()/1000=>start+delay)
    {
    a.position.x=a.position.x+5;
    }
    does not work. If the > "greater than sign is removed you get the movement but without the delay, just a contious motion. the spped is all that is controled in the statement "5.position.x+5". This is no different than if you used a.velocity.x=5. I may have missed something bret was trying to show me as I am new to this. What I want to do is move an object 10 pixels at a time with a delay of 1 second between positions. I WAS able to get the looping action to work but it DID slow the browser to a crawl after a few movements.

  10. #10
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681
    Hello again tomkat42,

    The slowing down you experienced is due to that memory leak I mentioned. Hopefully this will be corrected in the next release. This is also why I stated that using Bret's timer idea would be a better option.

    The code you have posted here won't work. The first line must be kept elsewhere in the movie and outside of the looping that is required here. eg. put the first line in the element's action list to initialise it. However, you also need to put a copy of the same line inside the 'if' statement to reset the 'start' value.

    Also, if you remove the '>' you will need to replace it with another '=' as in '=='. A single '=' is used in javascript to assign a value and a double '==' is used to compare two expressions. Also, the '=>' may not work and should probably be expressed instead as '>='.

    If you like and can take a look at your movie. If you are comfortable with that then please send your movie to ebrown@syssoft.net.au and/or you can download a couple of example movies from http://www.syssoft.net.au/3dfa/examples.zip

    In the examples I've used two techniques. One uses a timer and the other uses the 'Run nnn times per second' option. Both only move a Text element across the screen. Keep in mind that these are only two ways of achieving the same result. Other members of this forum would have different methods and ideas that would accomplish the same effect.

    I hope this helps to explain what I'm talking about and also helps you with your development. If not, let me know and I'll see what else I can do.

    Cheers,
    Ed



  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    not exact

    Originally posted by tomkat42
    the code that bret posted
    start=0 and delay=10 in main movie and a list of actions calling.............

    start=timer()/1000;
    if (timer()/1000=>start+delay)
    {
    a.position.x=a.position.x+5;
    }
    does not work. If the > "greater than sign is removed you get the movement but without the delay, just a contious motion. the spped is all that is controled in the statement "5.position.x+5". This is no different than if you used a.velocity.x=5. I may have missed something bret was trying to show me as I am new to this. What I want to do is move an object 10 pixels at a time with a delay of 1 second between positions. I WAS able to get the looping action to work but it DID slow the browser to a crawl after a few movements.
    I did say it was off the top of my head. I believe it should be >=.

    I didn't realize your delay was so short. I think I'd do is in a list of actions set the timing to 1 every second and then just have a get.property then set.property in the built in actions

    Seems this would be the simplest way to do this.

    Example with source:
    http://deadyeti.com/blanius/movie_324.html

  12. #12
    Senior Member kusco's Avatar
    Join Date
    Nov 2001
    Posts
    681

    no offence

    Bret,

    My apologies, no offence was meant in my previous reply...I think

    Your 'off the top of your head' replies in this forum are a goldmine! Don't stop!!!!

    Cheers,
    Ed

    PS. It's late here (or early), (1am == time() + for(bed)

  13. #13
    Member
    Join Date
    Jan 2001
    Posts
    54
    Thanks for your help guys! The last 3 examples was what I was looking for! The knowledge and help of you guys are making the learning curve for us newbies much easier. Keep up the good work and thanks for your help!

    Tomkat

  14. #14
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Re: no offence

    Originally posted by kusco
    Bret,

    My apologies, no offence was meant in my previous reply...I think

    Your 'off the top of your head' replies in this forum are a goldmine! Don't stop!!!!

    Cheers,
    Ed

    PS. It's late here (or early), (1am == time() + for(bed)
    Oh none taken trust me.

    Heck my real code is VERY sloppy as you have seen.

    This is what happens when you are self taught and have to try things out to see if they are a good idea.....


  15. #15
    Senior Member
    Join Date
    Jul 2001
    Posts
    173
    Hi guys -

    a few responses to the posts - most you've answered yourselves, so these might be just confirmation.

    1. RETURN can only be used inside a function. outside a function there is nothing to 'return' to.

    2. the code

    var i =i;
    i=0;for (i=0; i<100;i++)
    {
    debug i
    )
    a.position.x=a.position.x+5;

    is ok, but the } should be a ).
    The var i = i; wont work, as it doesn't know what the second i equals. You shouldn't need to specifcally declare the variable, either - the i=0 should do it fine.

    3. Memory leak in for loops - yep - well spotted. We know about this and are working to fix these leaks for the next version - our top priority.

    4. The 'great than or equal to' is >=

    5. Sorry if we've missed part of the thread, but if you want to move an object 10 pixels every 1 second, the easiest method is to do the following:
    A) new movie
    B) new object (say, devil computer from clipart)
    C) javascript element to get the handle - call it 'computer'
    D) list of actions element set to play 1 times per second
    E) inside the list of actions, a jsvscript element with this code
    computer.position.x = computer.position.x + 10

    this seems to work fine.

    Hope this helps

    Regards

  16. #16
    Senior Member
    Join Date
    Jul 2001
    Posts
    173
    Kusco, would you pls drop us an email at support@insanetools.com - thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center