How to access entities in CzmlDataSource after loading - cesiumjs

I want to access to some entities in my czml data source for keep tracking in the viewer but after the loading, as one of the options for camera. I know that I can access entities in my czml file while I am loading them, but I don't know how I can access to them after loading. Here I have an example:
var viewer = new Cesium.Viewer('cesiumContainer');
var czmlDataSource = new Cesium.CzmlDataSource();
viewer.dataSources.add(czmlDataSource);
czmlDataSource.load('../../SampleData/Vehicle.czml').then(function(){
var myEntity= czmlDataSource.entities.getById('Vehicle');
viewer.trackedEntity=myEntity;
});
This code works fine, but I want to give option to the viewer to choose the camera, then I need to have access to Vehicle after I finished loading, I tried several methods, but non of them works. I have some example bellow:
var viewer = new Cesium.Viewer('cesiumContainer');
var czmlDataSource = new Cesium.CzmlDataSource();
viewer.dataSources.add(czmlDataSource);
czmlDataSource.load('../../SampleData/Vehicle.czml');
var myEntity= czmlDataSource.entities.getById('Vehicle');
viewer.trackedEntity=myEntity;
Do you know how I can define an entity from those which are already in my czml file?

The reason your second block of code doesn't work appears to be simply because you haven't waited for the asynchronous load of the czmlDataSource.
Try modifying your second block of code, take off the last 2 lines and wrap them in a button onClick callback. If you click the button before the CZML is loaded, myEntity will be undefined and the camera won't change. If you click the same button again after the CZML loads, it should work fine.

Related

click event is not working in forge viewer

We have implemented the Autodesk Forge Viewer in our web application. We have displayed the Navisworks file in Forge Viewer.
On clicking the particular element/object in forge viewer, we need to get the Object ID of selected element.
We will use this Object ID for multiple purpose (like zooming, etc) in our application.
For this we have used the below selection changed event in our page but the below event is not working.
EventsTutorial.prototype.onSelectionEvent = function(event){
var currSelection = this.viewer.getSelection();
var domElem = document.getElementById('MySelectionValue');
domElem.innerText = currSelection.length;
};
Kindly help us to resolve this issue.
It seems you didn't register your function as a listener to the viewer. So I guess your function onSelectionEvent is never called.
You probably want to register a listener to either the SELECTION_CHANGED_EVENT(docs) or the AGGREGATE_SELECTION_CHANGED_EVENT(docs).
this.viewer.addEventListener(Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT, (args) => {
// do something
});

display only a specific content in AS3 code using webStage View

I'd like to display, in my app, only a part of a web page.
On this website, I'd like to display, in my app, only the div id "MovieCart".
What should I write in my as3 code in order to do so ?
For now, I have this line :
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
But, of course, it's displaying the fullwebpage.
EDIT
So, I've tried this :
webView.addEventListener(Event.COMPLETE,onComplete);
var res : String = ExternalInterface.call("function(){return document.getElementById('movieCart').outerHTML}");
var urlOfMovie: URLRequest = new URLRequest("http://www.cinecity.nc/Cinecity/Film/40567");
var loaderMovie:URLLoader = new URLLoader();
loaderMovie.load(urlOfMovie);
webView.loadString(res);
But, as it's an AIR app, ExternalInterface.call can't be call. Any idea ?
Here is one easy way you can accomplish this:
//First, load the full page as you're currently doing:
webView.addEventListener(Event.COMPLETE, webLoadComplete); //listen for when the load is finished
webView.loadURL("http://www.cinecity.nc/Cinecity/Film/40565");
//runs when the load finishes
function webLoadComplete(e:Event):void {
webView.removeEventListener(Event.COMPLETE, webLoadComplete); //stop listening
//second, invoke the following Javascript on the page which assigns the `MovieCart` element as the html for the whole document body
webView.loadURL("javascript:document.body.innerHTML = document.getElementById("MovieCart").outerHTML");
}
Disclaimer:
Keep in mind that scrapping content from websites is generally frowned upon and you may be infringing on peoples work/copyrights by doing so.

Copy an Image from Flex Application (Web) and paste it outside the application

I have a requirement that we should be able to copy an image displayed in our application, to Clipboard and paste it outside (Like on Excel).
I was trying the below code snippet (Inside a button Click).
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT,
byteArray, false);
The dataLoaded object is true, however it does not paste anything when tried on Excel or MsPaint.
Do we have any way to achieve this?
Thanks.
The code you are showing is not enough in itself to get a successful transfer. Like many other operations within the security sandbox of a FP app (web) this code can only respond to a direct user interaction. So your code without any valid context cannot work of course but if called within a mouse down listener for example (a true user generated mouse event, creating a fake mouseevent would still not work) it should respond correctly:
private function handleMouseClick(event:MouseEvent):void
{
Clipboard.generalClipboard.clear();
var dataLoaded:Boolean = Clipboard.generalClipboard.setData(ClipboardFormats.RICH_TEXT_FORMAT, byteArray, false);
}

AS3 , Facebook API - Can't retrieve image from event object after image loads

I am getting a mysterious result when trying to load profile images from a logged in Facebook user's friends list into an as3 canvas app. In pretty much every (non-facebook) application I've made where loading an image is required I use the following:
private function loadPic():void
{
var url:String = Facebook.getImageUrl(_friendslistObjectArray[_loadCount].id);
_picLoader = new Loader();
var req:URLRequest = new URLRequest(url);
_picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPicLoaded);
_picLoader.load(req);
}
private function onPicLoaded(evt:Event):void
{
_picLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onPicLoaded);
// grab image from loader event to use it
var image = evt.target.content;
trace("this trace won't even show up and the program silently fails unless the line above this is removed");
_loadCount++;
loadPic();
}
I can't retrieve the image from the event object, and I am given no error at all. It all just fails silently. If I remove the line var image = evt.target.content, the process runs through the whole array.
I can't think of any reason this would occur. Furthermore, if I look in firebug's net activity, I see I see the images get loaded as long as I do not have the line I just mentioned included. I just can't seem to get the image data from the event object to add it to stage or a container movieclip.
This should be very easy. I'm racking my brain here trying to figure out what I missed or what is wrong. Any thoughts? Thanks!
Found the answer:
This line:
Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
Placed right before _picLoader.load(req); fixes the problem.
It was a crossdomain error, but for some unknown reason the error did not report until I threw var image = evt.target.content; into a try/catch and read the error message.
Props to this post for the answer:
Load profile image from Facebook with Actionscript 3
the evt.target should be a LoaderInfo object, try the code here:
var image = (evt.targe as LoaderInfo).loader.content;

Trouble using Loader, can't access properties of loaded swf

May not have asked question correctly so I’m asking again. I’m using Flash AS3 with code in actions layer.
Main movieclip onstage is : design_mc. Within it is a movieclip already in place onstage with an instance name clipart_mc.
Now I’m also loading a ListBox to the stage and each time a selection is made from listbox myLoader9 is used to load selected .swf into design_mc.clipArt_mc.
Now within each of the .swf files loaded into design_mc.clipArt_mc there is a mc I’d like to color transform called color_mc.
So now the listbox is onstage and I make a selection that places heart.swf inside of design_mc.clipArt_mc. I want to access heart.swf so I did this:
var child:DisplayObject = myLoader9.content.contentLoaderInfo.content.color_mc;
var colorTrans3:ColorTransform = new ColorTransform();
var trans3:Transform = new Transform(child);
I still can not get to heart.swf. Can anyone help please?
Anne
I'm working with Embedded SWFs here, but I think it's the same. I can get my MovieClip from the Loader "content" property. Like this:
var myMC:MovieClip = MovieClip(myLoader9.content);
Try this way, instead of using "content.contentLoaderInfo.content".
:)
I got it. I gave the loader a name:
myLoader9.name = "currentClip";
Then I can target in main movie using:
var child:DisplayObject = MovieClip(parent).design_mc.clipArt_mc.getChildByName("currentClip").content.color_mc;