dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Get values of embedded object

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    55

    Get values of embedded object

    So here we go, I am making a videoplayer (and yes I have a reason to do it myself), though I'm stuck with getting the values out of the embed object.

    This is my html code:
    Code:
            <div class="videoplayer">
            	
                <embed type="application/x-shockwave-flash" src="vidPlayer.swf" id="vidplayer" name="vidplayer" bgcolor="#000" width="100%" height="100%" quality="high" allowfullscreen="true" allowscriptacces="always" flashvars="video=hancock.flv" />
                
            </div>
    and some css:
    Code:
    .videoplayer{width:400px;height:328px;}
    What I want is to read the width and height of this embed object in AS3, so the width should be 400 and height 300 as a var in as3.

    I know how to do it with the flashvars. however I can't seem to get the width of the loader as following

    Code:
    LoaderInfo(this.root.loaderInfo).width;
    Thanks in advance.
    Last edited by Mpjraaij; 10-29-2009 at 10:14 AM.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Those are not flashvars, but I think I get what you mean.

    You can use ExternalInterface to call a javascript function which will return the values. You can even embed the javascript function within the actionscript, but that's not necessary.

    For simplicity's sake, let's assume you have jQuery on the html page. You can add this function in javascript:
    Code:
    function getDimensions(id){
      var thing = $('#'+id); //get jQuery reference to the item by id
      return [thing.width(), thing.height()]; //return an array with width and height values
    }
    and you can call that method from actionscript like this:
    Code:
    function getWidthAndHeight():Rectangle{
      var rect:Rectangle = new Rectangle();
      if (ExternalInterface.available){
         var wh:Array = ExternalInterface.call('getDimensions', ExternalInterface.objectID);
         rect.width = wh[0];
         rect.height = wh[1];
      }
      return rect;
    }

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    55
    Thank you, I am trying this as we speak - however FireFox gives me some sort of security warning

    I tried it with a step back
    Code:
    <script type="text/javascript">
    	function sendToActionScript(value) {
             var value = "werkt";
    		 return value;
         }
    </script>
    Code:
    if(ExternalInterface.available)
    			{
    				ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
    			}
    
    private function receivedFromJavaScript(value:String):void
    		{
    			tf.appendText("blaat");
    		}
    Wouldn't it be better to embed it in the as3 so I don't get the error?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    What is the error, exactly? I've never recieved a security error from Firefox related to externalinterface.

    In the code you just posted, you have a javascript function to be called from actionscript, and an actionscript function to be called from javascript, but neither of them is actually called. Even if you do want both functions, you don't (and probably shouldn't) name them the same. It's confusing.

  5. #5
    Member
    Join Date
    Mar 2009
    Posts
    55
    It is in Dutch but maybe you recognize the setup:
    http://www.biisiin.com/error.png

    As for the coding I now have this
    Code:
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    function getDimensions(id){
      var thing = $('#'+id); //get jQuery reference to the item by id
      return [thing.width(), thing.height()]; //return an array with width and height values
    }
    </script>
    Code:
    var test:Rectangle = getWidthAndHeight();
    			tf.appendText(String(test.width));
    Code:
    		function getWidthAndHeight():Rectangle{
    			  var rect:Rectangle = new Rectangle();
    			  if (ExternalInterface.available){
    			     var wh:Array = ExternalInterface.call('getDimensions', ExternalInterface.objectID);
    			     if(wh)
    			     {
    				     rect.width = wh[0];
    				     rect.height = wh[1];
    			     }
    			  } else {
    			  	rect.width = stage.stageWidth;
    			  	rect.height = stage.stageHeight;
    			  }
    			  return rect;
    		}

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I can't figure out that error. It looks like it might think flash is trying to open a popup?

    That code looks better. I don't see why that wouldn't work. Can you tell if it's calling the javascript at all?

  7. #7
    Member
    Join Date
    Mar 2009
    Posts
    55
    It works in my webhost, thank you for that.

    As for that I know the problem now - I get that error on my local harddrive (in the html page - not via internet) (flash is trying to communicate with the internet). Is there anywhere I can set it to allow to connect?

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    When accessing a swf on the local harddrive, the sandbox prevents network connections. You can change that in the publish settings, but then you won't have access to other local resources.

    What I do is have a local instance of apache running so I can test it on a real server without having to actually put it on the internet.

  9. #9
    Member
    Join Date
    Mar 2009
    Posts
    55
    Ah well I'll figure that one out. It works for sure now thank you!

    http://biisiin.com/videoplayer/embed.html

    As you see I both have the flashvars and the width of the player in the topleft.

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