From Loader to Bitmap AS3 Flex - facebook

i'm trying to load images from Facebook Albums to my flex app, this is the code called when i click on a FB image:
private var loaderFB:Loader;
private var immCaricata:Bitmap = new Bitmap();
//Function where i pass the url of the FB image clicked
private function getFBImage(src:String):void{
var request:URLRequest;
loaderFB=new Loader();
request=new URLRequest(src);
loaderFB.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteFBget);
loaderFB.load(request);
}
private function onCompleteFBget(event:Event):void {
var bitmap_dataFB:BitmapData = new BitmapData(640, 480);
bitmap_dataFB.draw(loaderFB.content);
immCaricata = new Bitmap(bitmap_dataFB);
displayOut.addChild(immCaricata);
}
it doesn't work!
If i pass
displayOut.addChild(loaderFB); //instead displayOut.addChild(immCaricata);
It works like a charm!
My problem is that i need to pass loader content to that bitmap (immCaricata) cause i use it in different other functions.
I tried different solution, but probably i do some mistakes somewhere.
Could you please help me? Hope is all clear.
Thank you so much
EDIT:
The problem was not the syntax but the security policy file, i had to add it:
in init function:
Security.loadPolicyFile("http://graph.facebook.com/crossdomain.xml");
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
and then where i load the image
loaderFB=new Loader();
request=new URLRequest(src);
loaderFB.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteFBget);
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = true;
loaderFB.load(request,lc);
controlloImm = true;
Hope is clear and hope it helps someone else. :)

private var loaderFB:Loader;
private var immCaricata:Bitmap;
//Function where i pass the url of the FB image clicked
private function getFBImage(src:String):void{
var request:URLRequest;
loaderFB=new Loader();
request=new URLRequest(src);
loaderFB.contentLoaderInfo.addEventListener(Event.COMPLETE,onCompleteFBget);
loaderFB.load(request);
}
private function onCompleteFBget(event:Event):void {
immCaricata = event.target.content as Bitmap;
displayOut.addChild(immCaricata);
}
Try this if you dont wanna change the loaded image size, hope this will help

Related

Binding Image URIs via Image.SetBinding() not working properly

I'm using the following code snippet to bind a image url to a image object (used as one element in a ViewCell object).
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, "sImageUrl");
...
The images in the list, for which I'm using that cell view, are not loading always. I was not able to identify the exact reason for the problem, but I think the problem is the load-process (for loading the images from the url/internet)..
Maybe the problem could be solved by setting the url via new Uri(...) as described in the documentation
var webImage = new Image { Aspect = Aspect.AspectFit };
webImage.Source = ImageSource.FromUri(new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"));
Now my question: is there a workaround for binding a uri object? e.g.
...
Image Picture = new Image()
{
Aspect = Aspect.AspectFit,
HorizontalOptions = LayoutOptions.StartAndExpand
}; // ImageSource.FromUri(new Uri("sImageUrl")))
Picture.SetBinding(Image.SourceProperty, ImageSource.FromUri(new Uri("sImageUrl")));
...
I'm working with xamarin studio (version 6.1.2, build 44, update channel "beta", os x).
Would be great if someone got a tipp.
Thanks a lot,
Alex
after some more trying I found a solution.. I'm not sure if it's a secure / professional way.. But for now, it seems to work.
What I did: I implemented my own class "AsyncSrcImage", derived it from Image and added another bindable property:
public class AsyncSrcImage : Image
{
private static String sDefaultURL = "";
public static readonly BindableProperty AsyncImgUrlProperty = BindableProperty.Create(nameof(AsyncImgUrl), typeof(String), typeof(AsyncSrcImage), sDefaultURL);
public String AsyncImgUrl
{
get { return (String)GetValue(AsyncImgUrlProperty); }
set { SetValue(AsyncImgUrlProperty, value); }
}
}
Additionally I adjusted the rendering process with a custom renderer. There I'm loading the image source via new Uri(...) as described in the documentation:
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using System;
[assembly: ExportRenderer(typeof(AsyncSrcImage), typeof(AsyncSrcImageRenderer))]
public class AsyncSrcImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
AsyncSrcImage oImage = (AsyncSrcImage)Element;
if (oImage != null && oImage.AsyncImgUrl != "")
{
oImage.Source = ImageSource.FromUri(new Uri(oImage.AsyncImgUrl));
}
}
}
Maybe that helps other folks ;)

Need to create xul based frame in firefox extension build using xul

I want to create xul based frame in one of my firefox extension. The frame should look like https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/ui_frame
or
how to use below node js code in xul:
var { Frame } = require("sdk/ui/frame");
var frame = new Frame({
url: "./city-info.html"
});
In node.js, its working fine, but I dont know how to create the same thing with xul. Anybody can help?
thanks in advance.
You have provided very little detail as to what you desire. If all that you desire is to create an <iframe> in which you can load HTML content, then something along the lines of the following will do so:
//The URL of the HTML you desire to load.
let chromeUrl = '[Some URL here]';
//Whatever element you want the iframe placed under.
let parentEl = document.getElementById('foo');
//* Overlay and bootstrap (from almost any context/scope):
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
//Create the <iframe> use
//mainDocument for the XUL namespace.
let iframeEl;
if(options.useBrowser){
iframeEl = mainDocument.createElement('browser');
} else {
iframeEl = mainDocument.createElement('iframe');
}
iframeEl.id = id;
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
parentEl.appendChild(iframeEl);
The above code was taken from my answer to Firefox SDK Add-on with a sidebar on both the right and left at the same time, which creates sidebars. One option of how those sidebars are created is to have them contain an <iframe>.
Finally I got the answer:
let chromeUrl = 'YOUR HTML PAGE URL';
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
let iframeEl;
iframeEl = mainDocument.createElement('iframe');
iframeEl.id = "d";
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
iframeEl.setAttribute('height', '32px');
window.document.documentElement.appendChild(iframeEl);

Using play framework and scala how to display image path from database

How to display image on view page in play framework and scala application,
from image path from database? I know how to display image from file on statically , but i have no idea about how to do this. Please anyone have knew the answer please share here.
You can put some methods on your controller just like this.
I have a controller Profile and I added a method getImage(string id) to return the photo of the person from db...
public class Profile extends Controller {
public static void getImage(String id)
{
models.Person person = models.Person .findById(id);
if(person.photo!=null)
{
ByteArrayInputStream input = new ByteArrayInputStream(person.photo);
renderBinary(input);
return;
}
VirtualFile vf = VirtualFile.fromRelativePath("/public/images/no_photo.jpg");
File f = vf.getRealFile();
renderBinary(f);
}
}
on your View,
you can use
<img src=#{Profile.getImage(person.id)}>
Hope this will help you. :)

Autofocus does not work in form inside a partial view using MVC3 Razor

I am using MVC 3 Razor and I have a simple form in a PartialView [I am showing this as a popup window]. Some of the features are not working properly in PartialView. For example the autofocus attribute.
#Html.TextBoxFor(model => model.Code, new { style = "width:50px", maxlength = 4, autofocus = "" })
I have tried setting the focus through jQuery script but that doesn't work either.
$('#Code').focus();
Am I missing something? Do I have to import some scripts in my partial view for this to work?
Any help is greatly appreciated.
Thanks in Advance.
Update:
I found the problem... I was loading the window and then showing it after a delay of 700ms. I commented out the setTimeout line and it worked. It must be that the focus worked when form loaded but when I actually did the "open()" it lost focus again.
Previous Code
function openWindow(url, title) {
var window = $("#Window").data("tWindow");
window.ajaxRequest(url);
window.title(title);
setTimeout(showWindow, 700);
}
function showWindow() {
var window = $("#Window").data("tWindow");
window.open().center();
}
New Code
function openWindow(url, title) {
var window = $("#Window").data("tWindow");
window.ajaxRequest(url);
window.title(title).open().center();;
//setTimeout(showWindow, 700);
}
Thanks everyone for your replies. Hope it helps someone.
Try this code:
function openWindow(url, title) {
var window = $("#Window").data("tWindow");
window.ajaxRequest(url);
window.title(title).open().center();
//call after the content has been loaded from the Ajax request
document.getElementById('Code').focus();
}

JavaScript: Event listener on iFrame resize / height attribute change (FB comment box)

I have the following problem: I need to add an event listener for an iframe (a Facebook comment box) when it changes its height.
I can not access or change the contentWindow because it is cross domain. But there must be a callback function or something that changes the height attribute.
Is there a way to add an event listener on attribute changes or something? I alreade tried onResize and onChange.
I'm getting crazy with that... Anyone has an idea?
Thank you so much!!
Short answer: No.
However, you can use "postMessage" and "receiveMessage" to send from one iframe to another cross domain. (Of course, only if you have access to the iframed content - I suspect not as it's on facebook.)
In any case... for future help....
(on the iframed page)
var ii = {}
ii.window_height = 800;
var sendHeight = function () {
var window_height = $('body').outerHeight(true);
if (window_height != ii.window_height) {
ii.window_height = window_height;
window.parent.postMessage(ii.window_height, "http://containerDomain.com");
}
}
setInterval(sendHeight, 2000);
(on the container page)
function receiveMessage(evt) {
if (evt.origin === 'https://iframedDomain.com')
{
var iframe_content_height = evt.data;
$('#iframe_form').animate({height: iframe_content_height });
}
}
if ($.browser.msie) {
window.attachEvent('onmessage', receiveMessage);
} else {
window.addEventListener('message', receiveMessage, false);
}
Remember to change the domains in each script.
Note: that's using jQuery - It works, but I'm sure someone can write that better then me? Also not too proud of the interval checking the height... might update if i can.