dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Loading Omniture info from XML to AS3

  1. #1
    Senior Member joejubee's Avatar
    Join Date
    Sep 2000
    Location
    Atlanta/San Diego
    Posts
    186

    Loading Omniture info from XML to AS3

    Ok, so in my AS3, I have the following code that loads in XML content to the SWF:

    Code:
    var xml:XML;
    
    var urlLoader:URLLoader = new URLLoader();
    var urlRequest = new URLRequest("playlist.xml");
    urlLoader.load(urlRequest);
    urlLoader.addEventListener(Event.COMPLETE, onComplete)
    
    
    function onComplete (evt:Event):void
    {
    try
    {
    var xml:XML= new XML(evt.target.data);
    processXML (xml);
    }
    catch (evt:TypeError)
    {
    trace ("Could not parse text into XML");
    trace (evt.message);
    }
    }
    
    
    
    function processXML(xml:XML):void
    {
        for each (var property:XML in xml.vid) 
        {
    		trace(xml.vid.attribute("src"));
    		trace(xml.vid.attribute("thumb"));
    		trace(xml.vid.attribute("cap"));
            
            //if there will be always ony one record in xml file you can set flv
            //playback source here
            myVideo.source=xml.vid.attribute("src");
    	    myPoster.source=xml.vid.attribute("thumb");
    		captioning.source=xml.vid.attribute("cap");
    
            //rest of thing should be also handle here
            
            //if there will be more records
            //you should sotrt data first
        }
    }

    Now, here's where it gets tricky... I have four other "variables" that I'd like to get pulled into the AS. (They're used for Omniture Reporting) I have them highlighted in red below.


    Code:
    myVideo.addEventListener(MetadataEvent.CUE_POINT, cp_listener);
    myVideo.addASCuePoint(0.01, "sendOmnitureStart");
    myVideo.addASCuePoint(134.0, "sendOmnitureMidPoint");
    myVideo.addASCuePoint(266.0, "sendOmnitureEnd");
    
    
    function cp_listener(eventObject:MetadataEvent):void {
            trace("Elapsed time in seconds: " + myVideo.playheadTime);
            trace("Cue point name is: " + eventObject.info.name);
            trace("Cue point type is: " + eventObject.info.type);
    		var trap:String;
    		switch (eventObject.info.name) {
    			case "sendOmnitureStart":
    				trap = sendOmniture('Started Playback');
    				break;
    			case "sendOmnitureMidPoint":
    				trap = sendOmniture('Playback Midpoint');
    				break;
    			case "sendOmnitureEnd":
    				trap = sendOmniture('Finished Playback');
    				break;
    		
    		}
    		
    }
    
    function sendOmniture(eventName) {
    	trace(eventName);
    	
    	
    	var OmnitureURL:String = "XXXXXX=session&j=XXXXX&pageName=" + eventName + ": THIS IS THE MOVIE NAME" 
    	trace(OmnitureURL);
    	var omnitureCall:URLRequest = new URLRequest(OmnitureURL);
    	omnitureCall.contentType = "image/gif";
    	omnitureCall.method = URLRequestMethod.GET;
    	var loader:URLLoader = new URLLoader();
    	try
    	{
    		loader.load(omnitureCall);
    	}
    	catch (error:ArgumentError)
    	{
    		trace("An ArgumentError has occurred.");
    	}
    	catch (error:SecurityError)
    	{
    		trace("A SecurityError has occurred.");
    	}
    	//trace(omnitureCall);
    }

    So now, I have an XML doc that looks like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <playlist id="Here's The Video" >
     	<vid desc="Introduction to Biological Terrorism Agents" 
     		 src="Introduction.flv" 
     		 thumb="Introduction.jpg"
     		 cap="Introduction.xml"
    		 omName="Introduction Video"
    		 omStart="0.01"
    		 omMiddle="134.0"
    		 omEnd="266.0" />
    </playlist>
    So my question is, how do I get the three "om" items in the XML loaded into the areas of AS (that are red) above?

    Thanks!

    Joe
    Last edited by joejubee; 09-08-2008 at 09:59 AM.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    As example this line
    myVideo.addASCuePoint(0.01, "sendOmnitureStart");
    will become
    myVideo.addASCuePoint(Number(xml.vid.attribute("om Start"),"sendOmnitureStart");

    However, the line needs to be within the function, where the XML is parsed.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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