dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: href = xml doc url???

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    href = xml doc url???

    does anyone know how I can rewrite this script
    Code:
    var script:XML = 
    <script>
        <![CDATA[
                 function()
                 {
                    myLightWindow.activateWindow({href: 'wall.swf',
                                                 title: 'lightwindow',
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450}); 
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
        ExternalInterface.call(script); 
    }
    to recognise and load the url defined by my xml doc.

    this onclick command loads up the url in a new window

    Code:
    function p_click(me:MouseEvent) 
    {
    	var sp:Sprite = me.target as Sprite;
    	var s_no:Number = parseInt(sp.name.slice(8,10));
    	navigateToURL(new URLRequest(url_list[s_no]), url_target_list[s_no]);
    }

    but i don't know how to add it to the href??? anyone know how it should look?

    the current href - wall.swf is an absolute route to a swf that loads into the lightwindow - but i need the url from the xml doc to be loaded???

    how do i do that?

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Assuming that the first code quoted works (and it's an awesome way of embedding js in flash, if it does), this should work:
    Code:
    var script:XML = 
    <script>
        <![CDATA[
                 function(url)
                 {
                    myLightWindow.activateWindow({href: url,
                                                 title: 'lightwindow',
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450}); 
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
    	var sp:Sprite = me.target as Sprite;
    	var s_no:Number = parseInt(sp.name.slice(8,10));
    	//navigateToURL(new URLRequest(url_list[s_no]), url_target_list[s_no]);
            ExternalInterface.call(script, url_list[s_no]); 
    }

  3. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...aaah! perfect that 'does' indeed work - good shot 5TonsOfFlax!!!

    yes, first time i've seen that js method, but as I amble along in as3 that is the smae with a lot of things!!!

    cheers for that 5TonsOfFlax

  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...how do i call in the title and description to the lightwindow display?

    this is how it is set for the rollover text fields:
    PHP Code:
    description_list[s_no
    do i call it along with the navigatetourl? or in the 'script' section?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If you'll note, navigateToURL is actually commented out. So no, not there.

    You'll have to alter the javascript function to take parameters for those, and pass them in the ExternalInterface call. Exactly the same as I did with url.

  6. #6
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    okay - nice one - thanks for all the help

  7. #7
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    i know this is wrong - tried it but is this along the right or should the externalinterace call be written only the once?

    PHP Code:
    var script:XML 
    <
    script>
        <![
    CDATA[
                 function(
    url)
                 {
                    
    myLightWindow.activateWindow({hrefurl,
                                                 
    captiondescription_list,
                                                 
    author'anon',
                                                 
    height300,
                                                 
    width450}); 
                 }
                 ]]>
    </
    script>;

    function 
    p_click(me:MouseEvent)  
    {  
        var 
    sp:Sprite me.target as Sprite;
        var 
    s_no:Number parseInt(sp.name.slice(8,10));
        
    //navigateToURL(new URLRequest(url_list[s_no]), url_target_list[s_no]);
            
    ExternalInterface.call(scripturl_list[s_no]); 
            
    ExternalInterface.call(scriptdescription_list[s_no]); 


  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The call should be only once, because you're only calling the javascript function once. The structure of an ExternalInterface call is this:
    ExternalInterface.call(javascriptmethodname, argument1, argument2, etc)

    So your updated code looks like this:
    Code:
    var script:XML =
    <script>
        <![CDATA[
                 function(url, description_list)
                 {
                    myLightWindow.activateWindow({href: url,
                                                 caption: description_list,
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450});
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
        var sp:Sprite = me.target as Sprite;
        var s_no:Number = parseInt(sp.name.slice(8,10));
        ExternalInterface.call(script, url_list[s_no], description_list[s_no]);
    }

  9. #9
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...daaaammmn! you good!

    perfect - thanks a mill and good karma to you

  10. #10
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...okay so this is all working a treat now, now i am hoping to do one last thing, create galleries.

    i know this is done by adding rel="Category[Gallery]" to the link in html

    so i am wondering if rel: can't be defined via the xml?

    this is what i thought might work:

    Code:
    var script:XML =
    <script>
        <![CDATA[
                 function(url, title_list, description_list, rel_list)
                 {
                    myLightWindow.activateWindow({href: url,
                                                 title: title_list,
                                                 caption: description_list,
                                                 rel: rel_list,
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450});
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
        var sp:Sprite = me.target as Sprite;
        var s_no:Number = parseInt(sp.name.slice(8,10));
        ExternalInterface.call(script, url_list[s_no], title_list[s_no], description_list[s_no], rel_list[s_no]);
    }
    and changing my xml item to this

    Code:
    	<thumbnail filename="thumb_01.jpg" url="gallery/fische01.mov"  rel="Evolution?[Man]" target="_blank" 
    		title="Item No. or title" 
    		description="description of this thumbnail image and associated file" />
    but that didn't seem to do anything - i am guessing i need to set up xml list along with the others.

    but i don't know if i am doing it right...

    Code:
    var filename_list = new Array();
    var url_list = new Array();
    var url_target_list:Array = new Array();
    var rel_list:Array = new Array();
    var title_list = new Array();
    var description_list = new Array();
    var folder:String = "thumbnails/";
    
    var i:Number;
    var j:Number = 0;
    var k:Number = 0;
    var l:Number = 0;
    var m:Number = 0;
    var total:Number;
    var flashmo_xml:XML = new XML();
    var loader:URLLoader = new URLLoader();
    loader.load(new URLRequest("thumbnail_list_3.xml"));
    loader.addEventListener(Event.COMPLETE, create_thumbnail);
    
    function create_thumbnail(e:Event):void 
    {
    	flashmo_xml = XML(e.target.data);
    	total = flashmo_xml.thumbnail.length();
    	var anglePer:Number = ((Math.PI*2) * numOfRotations) / total;
    	
    	for( i = 0; i < total; i++ )
    	{
    		url_list.push( flashmo_xml.thumbnail[i].@url.toString() );
    		url_target_list.push( flashmo_xml.thumbnail[i].@target.toString() );
    		rel_list.push( flashmo_xml.thumbnail[i].@rel.toString() );
    		title_list.push( flashmo_xml.thumbnail[i].@title.toString() );
    		description_list.push( flashmo_xml.thumbnail[i].@description.toString() );
    ...well, i do know that i am not doing it right because it doesn't work

    anyone know what is a miss on this? or should i be adding something else elsewhere? or creating a specific function or something?

    i am wanting to create a similar set up to any of the links with gallery in the name here i want to allow the user to choose from the rel: defined galleries.

    all that i have tried is not giving much away!
    Last edited by WWFC; 02-06-2009 at 11:09 AM.

  11. #11
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I don't see anything obviously wrong with that. Have you tried calling the equivalent javascript function in your page outside of flash?

  12. #12
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...not sure how i should write it - but when i tweaked the as a bit - the lightwindow is opening up - seems to ignore the rel references?! is there something glaring within the whole thing...

    Code:
    import org.papervision3d.scenes.*;
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.materials.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    
    var container:Sprite = new Sprite();
    container.x = 400;
    container.y = 300;
    addChild(container);
    
    var scene:Scene3D = new MovieScene3D(container);
    var cam:Camera3D = new Camera3D();
    cam.zoom = 6;
    
    tn_title.text = "";
    tn_desc.text = "";
    tn_url.text = "";
    
    var p_dict:Dictionary=new Dictionary();
    var pc:Plane = new Plane();
    pc.visible = false;
    cam.target = pc;
    
    var numOfRotations:Number = 3;
    var yPos:Number = 0;
    var angle:Number = 0;
    
    var filename_list = new Array();
    var url_list = new Array();
    var url_target_list:Array = new Array();
    var rel_list = new Array();
    var title_list = new Array();
    var description_list = new Array();
    var folder:String = "thumbnails/";
    
    var i:Number;
    var j:Number = 0;
    var k:Number = 0;
    var l:Number = 0;
    var m:Number = 0;
    var total:Number;
    var flashmo_xml:XML = new XML();
    var loader:URLLoader = new URLLoader();
    loader.load(new URLRequest("thumbnail_list_3.xml"));
    loader.addEventListener(Event.COMPLETE, create_thumbnail);
    
    function create_thumbnail(e:Event):void 
    {
    	flashmo_xml = XML(e.target.data);
    	total = flashmo_xml.thumbnail.length();
    	var anglePer:Number = ((Math.PI*2) * numOfRotations) / total;
    	
    	for( i = 0; i < total; i++ )
    	{
    		url_list.push( flashmo_xml.thumbnail[i].@url.toString() );
    		url_target_list.push( flashmo_xml.thumbnail[i].@target.toString() );
    		title_list.push( flashmo_xml.thumbnail[i].@title.toString() );
    		description_list.push( flashmo_xml.thumbnail[i].@description.toString() );
    		
    		var bfm:BitmapFileMaterial = new BitmapFileMaterial(
    			folder + flashmo_xml.thumbnail[i].@filename.toString());
    		bfm.oneSide = false;
    		bfm.smooth = true;
    		var p:Plane = new Plane(bfm, 140, 105, 2, 2);
    		scene.addChild(p);
    		var p_container:Sprite = p.container;
    		p_container.name = "flashmo_" + i;
    		p_dict[p_container] = p;
    		p_container.buttonMode = true;
    		p_container.addEventListener( MouseEvent.ROLL_OVER, p_rollover );
    		p_container.addEventListener( MouseEvent.ROLL_OUT, p_rollout );
    		p_container.addEventListener( MouseEvent.CLICK, p_click );
    		
    		p.rotationY = (-i*anglePer) * (180/Math.PI) + 90;
    		p.x = Math.cos(i * anglePer) * 480;
    		p.z = Math.sin(i * anglePer) * 480;
    		p.y = yPos;
    
    		if( (i+1) % 20 == 0 )
    		{
    			 yPos += 115;
    		}
    	}
    }
    
    function p_rollover(me:MouseEvent) 
    {
    	var sp:Sprite = me.target as Sprite;
    	var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 1, 0.5, 0.6, true);
    	var s_no:Number = parseInt(sp.name.slice(8,10));
    	tn_title.text = title_list[s_no];
    	tn_desc.text = description_list[s_no];
    	tn_url.text = url_list[s_no];
    }
    function p_rollout(me:MouseEvent) 
    {
    	var sp:Sprite = me.target as Sprite;
    	var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 0.5, 1, 0.6, true);
    	tn_title.text = "";
    	tn_desc.text = "";
    	tn_url.text = "";
    }
    
    var script:XML =
    <script>
        <![CDATA[
                 function(url, title_list, description_list, rel_list)
                 {
                    myLightWindow.activateWindow({href: url,
                                                 title: title_list,
                                                 caption: description_list,
                                                 rel: rel_list,
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450});
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
        var sp:Sprite = me.target as Sprite;
        var s_no:Number = parseInt(sp.name.slice(8,10));
        ExternalInterface.call(script, url_list[s_no], title_list[s_no], description_list[s_no], rel_list[s_no]);
    } 
    addEventListener(Event.ENTER_FRAME, render);
    
    function render(e:Event):void
    {
    	var dist2:Number = ((stage.mouseX) - 400) * 0.0001;
    	angle += dist2;
    	cam.x = - Math.cos(angle) * 150;
    	cam.z = Math.sin(angle) * 150;
    	var new_zoom = 5; 
    	cam.zoom += ( new_zoom - cam.zoom ) * 0.06;
    	scene.renderCamera(cam);
    }
    it opens the clicked thumbnail url fine - but ignores anything to do with the rel param????
    Last edited by WWFC; 02-06-2009 at 11:26 AM.

  13. #13
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In that code you never push the value into rel_list. But you did in the previous code. Is it really there?

  14. #14
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...see what you mean - but if i put it back in and push it through - it stops the lightwindow opening???

    does that mean that maybe the xml itself is not properly formed?
    Code:
    	<thumbnail filename="thumb_01.jpg" url="gallery/fische01.mov"  rel="Evolution?[Man]" target="_blank" 
    		title="Item No. or title" 
    		description="description of this thumbnail image and associated file" />

  15. #15
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Could be, but I don't see that. It's debugging time. Put this trace in, just before the ExternalInterface call:
    Code:
    trace("rel is '"+rel_list[s_no]+"');
    You basically need to find out what javascript is actually getting called.

    Also, if you have firefox, you could look at the javascript console to see if any particular javascript error messages are showing up.

  16. #16
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    getting this from the ff error console

    Error: Permission denied to call method Location.toString

    that is when i run the as posted in it's entirity - is that just the push?

  17. #17
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...getting this for the trace

    Code:
    rel is 'Evolution?[Man]'
    that means it is there?

    with this as:

    Code:
    import org.papervision3d.scenes.*;
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.materials.*;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    
    
    var container:Sprite = new Sprite();
    container.x = 400;
    container.y = 300;
    addChild(container);
    
    var scene:Scene3D = new MovieScene3D(container);
    var cam:Camera3D = new Camera3D();
    cam.zoom = 6;
    
    tn_title.text = "";
    tn_desc.text = "";
    tn_url.text = "";
    
    var p_dict:Dictionary=new Dictionary();
    var pc:Plane = new Plane();
    pc.visible = false;
    cam.target = pc;
    
    var numOfRotations:Number = 3;
    var yPos:Number = 0;
    var angle:Number = 0;
    
    var filename_list = new Array();
    var url_list = new Array();
    var url_target_list:Array = new Array();
    var rel_list:Array = new Array();
    var title_list = new Array();
    var description_list = new Array();
    var folder:String = "thumbnails/";
    
    var i:Number;
    var j:Number = 0;
    var k:Number = 0;
    var l:Number = 0;
    var m:Number = 0;
    var total:Number;
    var flashmo_xml:XML = new XML();
    var loader:URLLoader = new URLLoader();
    loader.load(new URLRequest("thumbnail_list_3.xml"));
    loader.addEventListener(Event.COMPLETE, create_thumbnail);
    
    function create_thumbnail(e:Event):void 
    {
    	flashmo_xml = XML(e.target.data);
    	total = flashmo_xml.thumbnail.length();
    	var anglePer:Number = ((Math.PI*2) * numOfRotations) / total;
    	
    	for( i = 0; i < total; i++ )
    	{
    		url_list.push( flashmo_xml.thumbnail[i].@url.toString() );
    		url_target_list.push( flashmo_xml.thumbnail[i].@target.toString() );
    		rel_list.push( flashmo_xml.thumbnail[i].@rel.toString() );
    		title_list.push( flashmo_xml.thumbnail[i].@title.toString() );
    		description_list.push( flashmo_xml.thumbnail[i].@description.toString() );
    		
    		var bfm:BitmapFileMaterial = new BitmapFileMaterial(
    			folder + flashmo_xml.thumbnail[i].@filename.toString());
    		bfm.oneSide = false;
    		bfm.smooth = true;
    		var p:Plane = new Plane(bfm, 140, 105, 2, 2);
    		scene.addChild(p);
    		var p_container:Sprite = p.container;
    		p_container.name = "flashmo_" + i;
    		p_dict[p_container] = p;
    		p_container.buttonMode = true;
    		p_container.addEventListener( MouseEvent.ROLL_OVER, p_rollover );
    		p_container.addEventListener( MouseEvent.ROLL_OUT, p_rollout );
    		p_container.addEventListener( MouseEvent.CLICK, p_click );
    		
    		p.rotationY = (-i*anglePer) * (180/Math.PI) + 90;
    		p.x = Math.cos(i * anglePer) * 480;
    		p.z = Math.sin(i * anglePer) * 480;
    		p.y = yPos;
    
    		if( (i+1) % 20 == 0 )
    		{
    			 yPos += 115;
    		}
    	}
    }
    
    function p_rollover(me:MouseEvent) 
    {
    	var sp:Sprite = me.target as Sprite;
    	var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 1, 0.5, 0.6, true);
    	var s_no:Number = parseInt(sp.name.slice(8,10));
    	tn_title.text = title_list[s_no];
    	tn_desc.text = description_list[s_no];
    	tn_url.text = url_list[s_no];
    }
    function p_rollout(me:MouseEvent) 
    {
    	var sp:Sprite = me.target as Sprite;
    	var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 0.5, 1, 0.6, true);
    	tn_title.text = "";
    	tn_desc.text = "";
    	tn_url.text = "";
    }
    
    var script:XML =
    <script>
        <![CDATA[
                 function(url, title_list, description_list, rel_list)
                 {
                    myLightWindow.activateWindow({href: url,
                                                 title: title_list,
                                                 caption: description_list,
                                                 rel: rel_list,
                                                 author: 'anon',
                                                 height: 300,
                                                 width: 450});
                 }
                 ]]>
    </script>;
    
    function p_click(me:MouseEvent)  
    {  
        var sp:Sprite = me.target as Sprite;
        var s_no:Number = parseInt(sp.name.slice(8,10));
        trace("rel is '"+rel_list[s_no]+"'");ExternalInterface.call(script, url_list[s_no], title_list[s_no], description_list[s_no], rel_list[s_no]);
    } 
    addEventListener(Event.ENTER_FRAME, render);
    
    function render(e:Event):void
    {
    	var dist2:Number = ((stage.mouseX) - 400) * 0.0001;
    	angle += dist2;
    	cam.x = - Math.cos(angle) * 150;
    	cam.z = Math.sin(angle) * 150;
    	var new_zoom = 5; 
    	cam.zoom += ( new_zoom - cam.zoom ) * 0.06;
    	scene.renderCamera(cam);
    }
    why doesn't the rel work if it is tracing?!

  18. #18
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...and using that online - it doesn't open the lightwindow??

    do you think the array is causing the trouble?

    Code:
    var rel_list:Array = new Array();

  19. #19
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    No, I don't think the array is causing the trouble. I still don't see the problem. You should test that call in pure javascript to see whether it works there. I suspect that it won't.

  20. #20
    Senior Member
    Join Date
    Aug 2006
    Posts
    293
    ...hmmm - the plot thickens!

    you are right - it doesn't open the gallery links from my html page

    what does that mean? do i need to add something to the .js?

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