Exact clone of a TextureMaterial - actionscript-3

I want to clone a TextureMaterial, modify it and keep the original and the clone for later use.
What I did so far is following:
var BT:BitmapTexture = defaultMaterial.texture as BitmapTexture;
var BD:BitmapData = BT.bitmapData;
var clone:BitmapData = BD.clone();
var newBT:BitmapTexture = new BitmapTexture(clone);
transparentMaterial = new TextureMaterial(newBT, false, true);
transparentMaterial.lightPicker = defaultMaterial.lightPicker;
But the cloned TextureMaterial does not look like the original (see attachment). Can anyone help me with that problem please? I think i am missing some important information from the texture? uv-coordinates maybe or something like that.
I also posted my problem here with an additional image as attachment: http://away3d.com/forum/viewthread/5956/

I solved the Problem. It was just one wrong parameter. I enable mipmaping for the clone, but the original does not have mipmaping enabled.
The working Soulution looks like this:
clone = new TextureMaterial(original.texture, true, true, false);
clone.lightPicker = original.lightPicker;

Related

Can i send data from one website’s console to another?

So im trying to automate a task at work, and im wondering if theres anyway to send data from the console of one webpage to the console of another web page.
The task i am trying to automate consists of a website that has a prefilled form. I need to get elements from this form, and then copy them into another totally different website. Ive already written a script that pulls the data i need from the form and displays it in the console. Now I need to find a way to send the data (which is simply variables) to the other page’s console. Is this possible?
Keep in mind this is in a work computer, not allowed to download anything on it.
Are you an admin of the webpages and are these pages from the same site? if the answer is yes, i would recommend you use localStorage for saving and retrieving the data then display it to the console.
If it's not your website and you want it to work anyway just create a simple browser extension.
Here are some links to help you get started with extensions
MDN doc
Chrome doc
The idea is for you to target webpage A collect the data and post it to Github
Then target webpage B to read data from your github gist and you dispaly it in the console.
Cheers, i hope it was helpfull
Which server side language are you using ?
Usually for these, you could just have a form which is posting data to another website's form.
Look at this php example :
https://www.ostraining.com/blog/coding/retrieve-html-form-data-with-php/
Correct me If I did not understand your question correctly.
//Store the logs in following way
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
//copying the logs into a json file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
console.save(console.logs) //prints the logs in console.json file
// from the console.json file, you can use log information from another page
//Store the logs in following way
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
localStorage.setItem('Logs', console.logs);
localStorage.getItem('Logs'); // from any browser

How do you clone a cheerio object

I've got a cheerio object:
const $ = cheerio.load('<span class="layer-chunk"></span>')
This is a simple example it is far more complex.
I need to clone it so that I can do different things with it without actually effecting it.
This is what I've got so far:
const clone = $ => {
const strHtml = $('body').html()
return cheerio.load(strHtml)
}
const myClone = clone($)
But I am sure this is not a cheap op. There is a clone method in the docs but I cannot get it to work. I've tried this:
const myClone = $.root().clone()
But no cigar. Anyone know best practice for cloning a cheerio object? thanks
You can always just do:
cheerio.load($.html())
As shown in the documentation all you need to do is
const $ = cheerio.load('<div id="fruits">This is <em>content</em>.</div>')
const moreFruit = $('#fruits').clone()
or you can check cloneDom on the this link
Create a deep copy of the given DOM structure by first rendering it to
a * string and then parsing the resultant markup.
Thanks
I think in order to actually use the clone you have to do it like this:
cheerio('.layer-chunk', clone).text('something')
^^^^^

SoundCloud POST Comment Not Authorized

[UPDATE]
Problem fixed. Working code and method updated below!
So, I am trying to post a comment to a SoundCloud track using the SoundCloud api in AS3.
The documentation can be found here:
http://developers.soundcloud.com/docs/#comments
And my code is as follows:
var urlLoader:URLLoader = new URLLoader();
var urlString:String = "https://api.soundcloud.com/tracks/" + soundModel.currentlyPlayingItem.id + "/comments.json" + "?comment[body]=" + commentString + "&comment[timestamp]=" + trackPositionComment;
var urlRequest:URLRequest = new URLRequest(urlString);
urlRequest.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.oauth_token = soundModel.userToken; //here is the filler variable to make POST, not GET.
urlRequest.data = variables;
urlRequest.contentType = "application/x-www-form-urlencoded";
var header2:URLRequestHeader=new URLRequestHeader("oauth_token",soundModel.userToken);
var header3:URLRequestHeader=new URLRequestHeader("client_id", "sdjhb4jhbkjbe4gkjbh4random");
urlRequest.requestHeaders.push(header2);
urlRequest.requestHeaders.push(header3);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, commentPosted);
urlLoader.load(urlRequest);
Originally I was consistently getting a 401 - unauthorized error.
After playing around with the SoundCloud API console, I saw that there was a 'content-length' of 0, meaning no body. So all the authentication stuff had to be going in headers, not variables. However, with POST method in AS3 UrlLoader, it will automatically send as a GET if there is no body (variables) included. So for that reason I left an arbitrary variable value.
Also the two parameters, 'body' and 'timestamp' indeed have to be sent as 'comment[body]' and 'comment[timestamp]' even though this isn't quite made clear in the documentation. Also both of these parameters have to be included in the URL, and not as variables or headers.
Finally, to get a authorized return, you must provide both your 'client_id' and 'oauth_token' as headers.
It was this magic combination that did it for me. I hope this helps some other people, ready to rip their hair out like I was.
Thx,
Theo M.

as3 get vars from url

I found this post and I used the code almost exactly to how they suggested. It doesn't work. Do I need to add something in the php? What am I doing wrong?
Am I missing an import?
Thanks
Here is my code:
my php link is: www.mySite.com/example.php?id=true
var search:String = ExternalInterface.call("window.location.search");
var vars:URLVariables = new URLVariables(search);
if(vars.id)
{
/// Do something
}
Found answer here but doesn't work for me.
How to get/obtain Variables from URL in Flash AS3
You forgot to get rid of the page address:
var search:String = "www.mySite.com/example.php?id=true";
var vars:URLVariables = new URLVariables(search.substr(search.indexOf("?")+1));
if(vars.id) trace(vars.id);
Provided that you are sure that the address contains ? and actual variables you are looking for.

Encrypting configuration sections

I'm trying to programmatically encrypt configuration sections of App.config and Web.config files. In the following code, I set the path configuration file I want to edit in the configFilePath variable and then expect it to encrypt the connectionStrings section.
var config = ConfigurationManager.OpenExeConfiguration(configFilePath);
var section = config.GetSection("connectionStrings");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");
}
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");
This runs fine without any errors but makes no changes to the given file. It's like it's not really accessing the file I want to access.
Any ideas?
Right, answering my own question...
The code was indeed not opening the right config file. To do that we need to use ConfigurationManager.OpenMappedExeConfiguration() instead of ConfigurationManager.OpenExeConfiguration().
So, the first line of the code above changes to:
var map = new ExeConfigurationFileMap { ExeConfigFilename = configFilePath };
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);