A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: htm to flash javascript

  1. #1
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224

    htm to flash javascript

    Hi
    I have a navbar that of course gets used on several htm pages.
    I would like the flash to play a different part of an MC depending on which page its being displayed on. i.e. if the navbar is on page1.htm
    i want to have the .swf do
    _root.myclip.gotoAndStop("page1")
    if its on page2.htm then
    _root.myclip.gotoAndStop("page2") etc ...

    I've trawled through the tuts section, movies section searched everywhere i can think but havent quite found the answer tho' have come close but I havent managed to successfully convert anything.
    I dont seem to be able to write the correct javascript/actionscript combo
    can someone tell me what i should put in my htm and what i should put in my actionscript
    Thanks
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  2. #2
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    simplest method, imho:

    from html, use
    Code:
    document.getElementById('yourswfid').SetVariable('nameofvariable', newvalue);
    e.g.,
    Code:
    <html><body><span onclick="document.getElementById('yourswf').SetVariable('q', 1);">click</span></body></html>
    and recieve it in flash with
    Code:
    //in frame
    this.watch("nameofvariable", functionname);
    function functionname(a,b,c) {
    //a is the variable, b is the old value, c is the new value
    statments;
    return c;
    }
    e.g.,
    Code:
    this.watch("q", fn);
    function fn(a,b,c) {
    var o = new TextFormat("Tahoma", 48);
    _level0.createTextField("tf", 0, 0, 0, 200, 200);
    _level0.tf.text = c;
    return c;
    }
    (all untested)

    change the red bits at will, don't mess with the other stuff unless you're sure (e.g., failing to return the new value will cause failure).

  3. #3
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    Hi
    thanks for the help,
    this is what i did with it!
    in my htm

    <BODY onload="document.getElementById('texter2').SetVari able('pagename', hak);">

    on my fla frame

    // in frame
    this.watch("pagename", getpage);
    function getpage(pagename, b, c) {
    // a is the variable, b is the old value, c is the new value
    if (pagename == hak) {
    _root.texts.gotoAndPlay("hak");
    } else {
    _root.texts.gotoAndPlay("faal");
    }
    return c;
    }

    Please dont be confused by my use of 'text'/texter' etc, i'm not using text boxes.
    it didnt work and the browser throws up an javascript error faal/hak is undefined ....
    what did i do wrong?
    Last edited by suehami; 02-18-2005 at 03:40 PM.
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    forget about javascript in this context - it depends on the fact that your browser fires the onload event when the movie is already in a position to receive it ... whether it does so depends on the particular os / browser combination and possibly on loading speed.
    Rather add

    <embed src="nav.swf" flashvars="page=page1" ...
    and its object counterpart to your html pages. The movie will have the variable page on the main timeline set to page1

    Musicman

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    i think is because you're passing a string as the second arugment of the SetVariable, but either way musicman's right and his solution is better for your situation in pretty much every regard.

  6. #6
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    Moagruis and musicman
    thankyou both so much for your help. I had kinda realised that trying to set it up using the javascript probably wasn't goig to work.

    can you explain a bit more how i should implement musicman's suggestion. I've tried it out but dont seem to be getting very far,.

    i put this to the html page: (page2 on page2.htm page3 on page3.htm etc)

    <embed src="Fullnavbar.swf" flashvars="page=page1" ..... etc

    then this (plus some) to the flash on a frame in the main timeline:

    page = "off";
    if (page ==" page1") {
    _root.buttonBar.txthilite.gotoAndPlay("hak");
    } else if (page == "page2") {
    _root.buttonBar.txthilite.gotoAndPlay("faal");
    } else if (page == "page3") ...... etc

    i guess i'm not setting the var correctly in the flash, and should i put the if/elseif onto a MC or into a function? can you show me how to set it up properly.
    thanks again.
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  7. #7
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    You also have to set the variables in the OBJECT tag and not just the EMBED tag.

    http://www.macromedia.com/cfusion/kn...fm?id=tn_16417

    And why are you setting the page to "off" and then checking it to see if it equals "page1", "page2", etc...

  8. #8
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    the javascript will work, it's just a bit more code than musicman's suggestion. if you're still having trouble, there are samples and source files here: http://qozix.com/dev/js2mx

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi Moagrius,

    the difference between this example and suehami's problem is just timing: you can certainly click a button once the website is loaded ... but you cannot be sure that the movie is loaded when the browser calls onload function
    Another potential problem: it is possible that the movie tries to go to a frame, following the if(page == "page1") code, that is not yet loaded.
    The behaviour of flash player in both cases is simply _undefined_

    Musicman

  10. #10
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    hi musicman,

    not to be contentious, but the onload function fires only after the page has loaded in it's entirety - and so would work if i understand the problem correctly.

    i believed this to be the case, but did a simple test to verify using a 4mb jpeg and some basic stop/goto actions with keyframes (something i'm not used to). i can upload the source if you'd be interested.

    even so, the original poster is still better off using your solution - mine's offered as an alternative and in some small defense of javascript

  11. #11
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    hi all
    thanks again for your input:
    oldnewbie, i put the 'off' as the default, but i can see why thats nonsense I've now added the param to the object tag:

    <param name="FlashVars" value="page=page1">
    <embed src="Fullnavbar.swf" FlashVars="page=page1" ........ etc


    I'm still not getting it to work; Please can you assume (correctly) that my actionscripting knowledge is limited to cut and paste and gotoAndPlay and my comprehension of how vars work is zilch.

    this is my code on the flash:

    var page;
    if (page=page1) {
    _root.buttonBar.hilite.gotoAndStop("hak");
    } else if (page=page2) {
    _root.buttonBar.hilite.gotoAndStop("faal");
    etc etc ....
    Can you please tell me have i got the var set right, should i have quotes on the "page1" should i have brackets after the var page ();?
    etc ....
    i've tried all kinds of combination, looked at tuts/helpfiles etc but i'm getting nowhere fast!
    thanks again
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  12. #12
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    hi all
    just to let you know i made some progress and now have the var being read by the flash .... not quite working properly yet but getting there

    I'm checking that the FlashVars is being read by using a text box with the var name page which is outputting the right page i.e. on page1 it shows page1 etc. But its not doing the gotoAndStop part. what happens is that the first line of the code is happening whatever 'page' == i.e. it always shows the img from the frame labelled off.... heres my code: which is on an empty MC.
    Code:
    onClipEvent (load) {
    	page;
    	
    	if (page==page1) {
    		_root.buttonBar.hilite.gotoAndStop("off");
    	} else if (page==page2) {
    		_root.buttonBar.hilite.gotoAndStop("faal");
    	} else if (page==page3) {
    		_root.buttonBar.hilite.gotoAndStop("talep");
    	} else if (page==page4) {
    		_root.buttonBar.hilite.gotoAndStop("Refs");
    	} else if (page==page5) {
    		_root.buttonBar.hilite.gotoAndStop("ilet");
    	} else if (page==page6) {
    		_root.buttonBar.hilite.gotoAndStop("hiz");
    	} else if (page==page7) {
    		_root.buttonBar.hilite.gotoAndStop("hak");
    	}
    }
    many thanks for all your help.
    Last edited by suehami; 02-20-2005 at 01:48 PM.
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  13. #13
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    try using _root.page and "page1" instead. Also the line with just page; in it does not make any sense

    Code:
    onClipEvent (load) {
    	
    	if (_root.page=="page1") {
    		_root.buttonBar.hilite.gotoAndStop("off");
    	} else if (_root.page=="page2") {
    		_root.buttonBar.hilite.gotoAndStop("faal")
    Musicman;

  14. #14
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    Hi Musicman
    I tried your suggestion but still not getting it to work. Am I doing something fundementally wrong? All of the tuts/examples I've ploughed through seem to only use the FlashVars to populate a text box, but I'm sure it will work
    Why isnt the var 'page' being properly recognised by the if/ else if statements but the text box is reading it ...........
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

  15. #15
    Senior Member suehami's Avatar
    Join Date
    Jun 2003
    Location
    asmania
    Posts
    224
    just in case anyone comes across this in a search or whatever and found it useful:
    Musicmans suggestion worked, dont know why it didnt work last night but this am it did .....
    thanks again all for your help.
    Only after the last tree has been cut down, after the last river has been poisoned, after the last fish has been caught, then will you find that money cannot be eaten. Cree Indian Prophecy.

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